validator icon indicating copy to clipboard operation
validator copied to clipboard

Attempted import error: 'validate' is not exported from 'csstree-validator'.

Open prathamesh-bigpi opened this issue 3 years ago • 4 comments

I have installed "csstree-validator": "^3.0.0", version and imported in react application import { validate } from 'csstree-validator'; Trying to run it but getting following error Attempted import error: 'validate' is not exported from 'csstree-validator'. csstree_validator__WEBPACK_IMPORTED_MODULE_13__.default.validate is not a function

After changing import statement to import { validate } from 'csstree-validator/lib/validate'; the code is working fine. Is this a known issue ?

Note: version 2.0.1 is working fine.

prathamesh-bigpi avatar Jun 20 '22 15:06 prathamesh-bigpi

Same issue, using [email protected], upgraded my webpack to version 5 and getting

Error: Module not found: Error: Package path ./dist/csstree-validator.js is not exported from package node_modules/csstree-validator (see exports field in node_modules/csstree-validator/package.json)

if using import { validate } from 'csstree-validator';, getting this

./node_modules/csstree-validator/lib/helpers.js:2:0-37 - Error: Module not found: Error: Can't resolve 'path' in '/Users/kpavlenko/projects/communication-app/node_modules/csstree-validator/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

cakeinpanic avatar Apr 17 '23 08:04 cakeinpanic

@prathamesh-bigpi if you are using webpack 4, this may help you(used to work for us before an upgrade) import { validate } from 'csstree-validator/dist/csstree-validator.esm.js';

cakeinpanic avatar Apr 17 '23 08:04 cakeinpanic

btw your solution does not work for me neither :(

cakeinpanic avatar Apr 17 '23 08:04 cakeinpanic

Same issue here. It doesn't even work when I use require:

 [ERROR] Could not resolve "fs"

    node_modules/csstree-validator/cjs/helpers.cjs:3:19:
      3 │ const fs = require('fs');
        ╵                    ~~~~

  The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "--platform=node" to do that, which will remove this error.

✘ [ERROR] Could not resolve "path"

    node_modules/csstree-validator/cjs/helpers.cjs:4:21:
      4 │ const path = require('path');
        ╵                      ~~~~~~

  The package "path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "--platform=node" to do that, which will remove this error.

ba32107 avatar Feb 19 '24 21:02 ba32107