"plugin:node/recommended" generates: Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
See original GitHub issueThere was another issue like this, seen here: https://github.com/mysticatea/eslint-plugin-node/issues/135 but it was closed. But I felt it was warranted to open a new issue since this seems to be a problem with this plugin, which goes against the answer in that issue.
I have the following configuration:
"extends": [
"airbnb-base",
"plugin:node/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:jsdoc/recommended",
"plugin:prettier/recommended"
],
If I remove "plugin:node/recommended",
, the error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
goes away. So it is this plugin generating this error somehow.
The reason why I get this is because I use commonjs (i.e. require()
) instead of ecmascript modules (i.e. import
) in my code. But for Jest test cases, I use import
because those are transformed by babel anyway. So I get the error in those files only.
I can work around this by setting an overrides to use another sourceType
like so:
"overrides": [{
"files": ["path/to/some/file.js", "path/to/some/folder/**.js"],
"parserOptions": {
"sourceType": "module"
}
}]
But the question is, why is this error generated at all due to the inclusion of "plugin:node/recommended",
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Your workaround (overrides
parserOptions.sourceType
) is right.But it may be nice to use
plugin:node/recommended-module
instead.node/no-unsupported-features/es-syntax
rule to ignore ES modules syntax.Or, if you are sure that all
*.js
files are ES modules, you can useplugin:node/recommended-module
instead ofplugin:node/recommended
:I’d suggest using “unflagged” and not “not experimental”, personally. It’s fully usable with no experimental warning in node v12.17.