-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
'import()' expressions are not supported yet on Node engine >=14.5.0 #250
'import()' expressions are not supported yet on Node engine >=14.5.0 #250
Comments
I just ran into this, myself. I took at look at the rule, and we have: /lib/rules/no-unsupported-features/es-syntax.js const features = {
/* ... */
//--------------------------------------------------------------------------
// ES2020
//--------------------------------------------------------------------------
/* ... */
dynamicImport: {
ruleId: "no-dynamic-import",
cases: [
{
supported: null,
messageId: "no-dynamic-import",
},
],
},
} As @Tzahile said, Node 14 supports ECMAScript Modules without a flag. Are we just missing the correct Looking at the history at the official documentation (https://nodejs.org/docs/latest-v15.x/api/esm.html), it looks like the command line flag requirement was dropped as early as Node.js 12.17.0 and 13.2.0. I suppose it does depend on what you guys consider to be "supported", though. While the command line flag was removed a while ago, the feature only became "stable" as of version 15.3.0, which you can also see in that table. I suppose, in my opinion, features that work without a flag are supported enough to not have a linting rule complain about their use. Thoughts? |
Incidentally, I'd be happy to make a PR for this, but I don't want to just submit one without any chance of it getting merged. |
I also ran into this issue, please make a PR, someone will merge it! |
I think you may be able to revert a5f3ab2, which reverted 0b0c2aa, which added supported versions for ESM and dynamic import. Although, I think it could specify I'm not sure why the original commit was reverted. @mysticatea was there an issue with the original commit? |
The semver range for node ESM support without a flag is |
Based on my own testing, I found that it parses without flag since Node 10 (and I expect Node 8 as well, but not verified).
Note no flags passed, and no syntax error. Upon reaching such a statement, naturally, a run-time error is found:
Based on this, I was able to add support for ESM imports in QUnit whilst upholding Node 10 support, and without any complexity such as duplicate files or multiple entry point wrappers. Mocha has done the same. And both of these projects are passing CI with Node 10 without experimental flags (and both make sure the statement is not generally reached when under Node 12.17). Perhaps I have missed a corner case where this fails on Node 10, in which case I'd very much like to know so that we can defend against that issue! (Apologies if this is about something different than what this issue is about.) |
It'd be reasonable for this plugin to warn on it when it doesn't work tho, as opposed to just when it doesn't parse. |
@ljharb I took me by surprise because the rule refers to itself as I don't specifically have a preference for a rule that checks only syntax, nor do I have a preference to it actually helping understand spec-compliant runtime behaviour. Having just one rule that checks whatever we think is most useful, seems fine by me. Perhaps the author already meant for the rule to do more than check syntax, I don't know. The tool would be equally useful to me whichever way this goes. I'm merely raising that I found its behaviour surprising, and wanted to make sure the author/maintainers check if that is indeed the way they want it to behave. |
Okay all, here it is: I ended up doing a small refactor that allows more-complex semver strings for rule cases that is hopefully not too controversial. Let me know what you guys think, and hopefully someone notices it and wants to merge it! |
@mysticatea Any thoughts on this? |
note: dynamicImport eslint rule is caused by eslint-plugin-node bug mysticatea/eslint-plugin-node#250
/cc @ljharb @mysticatea friendly ping |
I don’t maintain this plugin; no point pinging me. |
To anyone following this issue, the change in #256 has been merged over in https://github.com/weiran-zsd/eslint-plugin-node as eslint-community#13. It looks like, until there's any movement on this repository and we hear from @mysticatea, we're trying to keep this alive over there. |
…yntax` when loading plugins based on mysticatea/eslint-plugin-node#250
…yntax` when loading plugins based on mysticatea/eslint-plugin-node#250
Hello,
I'm using Node 14 and all of my project is managed as a module (
"type": "module"
in package.json).Until now, using everywhere imports and exports, I didn't see this error.
Lately I added a dynamic import to some new code like the following:
Suddenly I got
'import()' expressions are not supported yet
error.I have
ecmaVersion
field set to 2021,and
"engines": { "node": ">=14.5.0" }
According to the README of this rule, it should be enough
Node 14 fully supports ESM
Thanks in advance!
The text was updated successfully, but these errors were encountered: