Closed frankthelen closed 6 years ago
it works with:
"import/extensions": [
"error",
"always",
{
"js": "never",
"jsx": "never",
"mjs": "never"
}
]
Same situation here. In my .eslintrc.js
I have basically the same thing:
'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 .mjs
, try the following:
// .eslintrc.js
exports.settings = {
"import/resolver": {
node: { extensions: [ .js, .mjs ] }
}
}
Is .mjs
canonized by a particular node version? I'm guessing it wouldn't hurt to add it as a default, but would love a link to Node docs stating that .mjs
is valid/preferred.
@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.