babel / babel-preset-env

PSA: this repo has been moved into babel/babel -->

Home Page:https://github.com/babel/babel/tree/master/packages/babel-preset-env

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynami import doesn't work when loose mode is disabled

sqal opened this issue · comments

commented

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 error Critical dependency: the request of a dependency is an expression
  • Open .babelrc and in set loose option to true, 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 :)

commented

I guess it's webpack's issue not babel. Sorry for posting this in the wrong place.