Dynami import doesn't work when loose mode is disabled
sqal opened this issue · comments
I tried to upgrade my project's dependencies to babel 7.x and babel-preset-env 2.0 but I am getting some error when I use dynamic import with a passed variable.
Input Code
const MODULES = {}
function registerModule(name) {
return import(`./modules/${name}/index.js`).then((m) => {
MODULES[name] = m.default
})
}
registerModule('a')
Babel Configuration (.babelrc, package.json, cli command)
.babelrc
{
"presets": [
["env", {
"modules": false,
"debug": true
}]
],
"plugins": [
"syntax-dynamic-import"
]
}
package.json
{
"name": "babel-bug-repo",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"build": "webpack",
"watch": "webpack -w"
},
"dependencies": {},
"devDependencies": {
"babel-core": "7.0.0-beta.2",
"babel-loader": "^7.1.2",
"babel-plugin-syntax-dynamic-import": "7.0.0-beta.2",
"babel-preset-env": "2.0.0-beta.2",
"webpack": "^3.6.0"
}
}
Steps to reproduce
- You can just clone the repo https://github.com/sqal/babel-preset-env-2-bug-repo
npm install && npm run build
- you should see errorCritical dependency: the request of a dependency is an expression
- Open .babelrc and in set
loose
option totrue
, build project again - no error this time
Expected Behavior
Should compile without errors.
Current Behavior
WARNING in ./src/index.js
4:9-55 Critical dependency: the request of a dependency is an expression
Your Environment
software | version(s) |
---|---|
Babel | 7.0.0-beta.2 |
babel-preset-env | 2.0.0-beta.2 |
node | 8.5.0 |
npm | 5.3.0 |
Operating System | Windows 10 |
Thank you for talking a look at my issue :)
I guess it's webpack's issue not babel. Sorry for posting this in the wrong place.
This is fixed by webpack/webpack#5679