-
Notifications
You must be signed in to change notification settings - Fork 66
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()
argument shouldn't be evaluated in the arrow scope
#84
Comments
That's a great catch and seems like a very trivial fix. Want to submit a PR? |
This seems to break Webpack's dynamic imports and code splitting. Since Webpack no longer sees a prefixed string in Has anyone else had issues with "Critical dependency: the request of a dependency is an expression" ? This SO question covers my problem exactly, but the solution was not sufficient: https://stackoverflow.com/questions/61719327/how-to-use-an-expression-in-an-import-with-babel-webpack |
The solution is "don't use this plugin with webpack": webpack supports dynamic imports (since version 3 I think), so you don't need to transpile them. Also this plugin wasn't meant to be used with webpack in the first place (hence |
I didn't explicitly bring this plugin into my build - something else must have. I will go hunting there. Thanks for your reply! |
If you are using Babel 7.12, you could try with
(example: it will show the resolved config, and you can share the log output if you need help understanding it. |
Downside is that there is no plugins listed here at all, seems I've made a mistake. Must be something built into babel/core transpiling my requires exactly the same way as this commit does. {
"inputSourceMap": {
"version": 3,
"file": "src/js/site.ts",
"sourceRoot": "/home/josh/projectDir/",
"sources": [
"src/js/site.ts"
],
"names": [],
"mappings": "/* removed */",
"sourcesContent": [
/* removed */
]
},
"sourceRoot": "/home/josh/projectDir",
"filename": "/home/josh/projectDir/src/js/site.ts",
"sourceMap": true,
"babelrc": false,
"presets": [
[
"@babel/preset-env",
{
"targets": "cover 99.5% in NZ, IE 11, iOS >= 9, Safari >= 9, not IE <= 10",
"modules": "auto",
"debug": false,
"useBuiltIns": "usage",
"corejs": 3
}
]
]
} |
Reproduction
Output
As you can see in the output code, the first assertion fails because
i++
is evaluated asynchronously, and the second one is a syntax error becauseawait
is inside a non-arrow function.Proposed output
We can pass the import argument in
Promise.resolve
, so that it is in the correct scope:The text was updated successfully, but these errors were encountered: