如何解决babel错误:“意外的令牌'导入'”

时间:2019-01-03 15:52:08

标签: javascript webpack babeljs babel

从6升级到babel 7后出现错误。

启动命令:webpack ./run/start.web.js提示我错误:

导入'./run/global';
SyntaxError:意外的令牌导入

看起来像babel的问题。

我的start.web.js仅由es6导入组成:

import './run/global';

我将.babelrc从v6升级到v7:

{
  "presets": [
[
  "env",
  {
    "modules": false,
    "targets": {
      "node": "10.13.0",
      "chrome": "49",
      "edge": "14",
      "firefox": "52",
      "safari": "10",
      "ie": "11"
    }
  }
],
 "react"
],
"plugins": [
  "@babel/plugin-syntax-dynamic-import",
  "@babel/plugin-transform-object-assign",
  "@babel/plugin-proposal-object-rest-spread",
  "@babel/plugin-transform-modules-commonjs",
  ["fast-async", {
    "compiler": {
      "promises": true,
      "generators": false,
      "noRuntime": true,
      "wrapAwait": true
    },
    "useRuntimeModule": false
  }],
  [
    "babel-plugin-root-import", {
    "rootPathPrefix": "~",
    "rootPathSuffix": "src"
  }]
],
"env": {
  "test": {
    "plugins": [
      "@babel/plugin-transform-modules-commonjs",
     ]
   }
 }
}

我的package.json具有最新的@ babel / core依赖性:

"devDependencies": {
  "@babel/core": "^7.2.2",
  "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
  "@babel/plugin-syntax-dynamic-import": "^7.2.0",
  "@babel/plugin-transform-modules-commonjs": "^7.2.0",
  "@babel/plugin-transform-object-assign": "^7.2.0",
  "@babel/plugin-transform-runtime": "^7.2.0",
  "@babel/polyfill": "^7.2.5",
  "@babel/preset-env": "^7.2.3",
  "@babel/preset-react": "^7.0.0",
  "@babel/preset-stage-0": "^7.0.0",
  "babel-eslint": "^10.0.1",
  "babel-loader": "^8.0.4",
  "babel-plugin-dynamic-import-node": "^2.2.0",
  "babel-plugin-root-import": "^6.1.0",
  "babel-plugin-system-import-transformer": "^3.1.0",
  "babel-plugin-transform-class-properties": "^6.24.1",
  "babel-root-import": "^4.1.8"
}

0 个答案:

没有答案