Как исправить ошибку babel: «Неожиданный токен« import »» - PullRequest
0 голосов
/ 03 января 2019

Я получаю сообщение об ошибке после обновления до версии 7 из 6.

Команда запуска: webpack ./run/start.web.js выдает ошибку:

import './run/global';
Ошибка синтаксиса: неожиданный импорт токена

Похоже на проблему с бабелом.

Мой 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",
     ]
   }
 }
}

My 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"
}
...