-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
import statement without .mjs
file extension causes linter errors
#939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
it works with:
|
Same situation here. In my 'import/extensions': ['error', 'always', {
js: 'never',
mjs: 'never',
}], ... but get the same 2 errors, "unable to resolve path to module" and "missing file extention". |
@maxmilton my guess is, once the module will be resolved, if it has the .mjs (or js) extension the other error will disappear. |
The Node resolver is not (yet) configured by default to look for // .eslintrc.js
exports.settings = {
"import/resolver": {
node: { extensions: [ .js, .mjs ] }
}
} Is |
@benmosher that fixes the problem! Thank you! I tried tweaking the settings but somehow wasn't able to come to that... seams simple enought though in hindsight. The documentation was a bit sparse around this. FYI for anyone in the future, this is what I used to resolve my issue: module.exports = {
settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs'] }
}
},
rules: {
'import/extensions': ['error', 'always', {
js: 'never',
mjs: 'never',
}],
}
} |
@benmosher it's behind a flag in node 8.5+; altho it's technically "experimental", it's not going to change much - mjs is the way forward. |
Hi!
I have a simple ESM module file
test.mjs
with this content:And a file
index.mjs
that loads the module like this:ESLint will produce the following errors:
Loading the module with file extension fixes the errors:
However, omitting the file extension remains best practice, as far as I know.
I am using Node 8.6.0 (with
--experimental-modules
to run ESM), eslint 4.8.0 and eslint-plugin-import 2.7.0.I tried the following tweaks in
.eslintrc
:"import/extensions": [2, { "js": "never", "json": "always", "mjs": "never" }]
prevents theimport/extensions
error -- which is good"import/extensions": [".js", ".mjs"]
does not help, the errorimport/no-unresolved
remainsThank you.
The text was updated successfully, but these errors were encountered: