Сборка узла не удалась с помощью babel, выдает ошибку: Требуется Babel "^ 7.0.0-0", но был загружен с "6.26.0" - PullRequest
0 голосов
/ 22 сентября 2018

Я пытаюсь создать приложение для узлов с помощью babel, но оно выдает ошибку.

Ошибка: требуется Babel "^ 7.0.0-0", но загружено с "6.26.0",Если вы уверены, что у вас есть совместимая версия @ babel / core, вероятно, что-то в процессе сборки загружает неправильную версию.Проверьте трассировку стека этой ошибки, чтобы найти первую запись, в которой не упоминается "@ babel / core" или "babel-core", чтобы увидеть, что вызывает Babel.

at throwVersionError (E:\mern-master\node_modules\@babel\helper-plugin-utils\lib\index.js:65:11)
at Object.assertVersion (E:\mern-master\node_modules\@babel\helper-plugin-utils\lib\index.js:13:11)
at _default (E:\mern-master\node_modules\@babel\plugin-proposal-object-rest-spread\lib\index.js:41:7)
at E:\mern-master\node_modules\@babel\helper-plugin-utils\lib\index.js:19:12
at Function.memoisePluginContainer (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:113:13)
at Function.normalisePlugin (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:146:32)
at C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
at OptionManager.mergeOptions (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
at OptionManager.init (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at File.initOptions (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:212:65)
at new File (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:135:24)
at Pipeline.transform (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transform (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\util.js:50:22)
at Object.compile (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\util.js:59:12)
at write (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\dir.js:21:21)
at handleFile (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\dir.js:43:7)
at C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\dir.js:61:9
at Array.forEach (<anonymous>)
at handle (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\dir.js:59:29)
at Array.forEach (<anonymous>)
at module.exports (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\dir.js:69:15)
at Object.<anonymous> (C:\Users\PranayKumar\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\index.js:129:1)
at Module._compile (internal/modules/cjs/loader.js:702:30)

npmERR!код ELIFECYCLE npm ERR!errno 1 npm ERR!mern-ecommerce@1.0.0 build: mkdir build && babel server/ -d build/server --ignore ./server-entry.js npm ERR!Статус выхода 1 npm ERR!нпм ERR!Сбой в сценарии сборки mern-ecommerce@1.0.0.нпм ERR!Это, вероятно, не проблема с npm.Скорее всего, выше вывод журнала.

npm ERR!Полный журнал этого прогона можно найти в: npm ERR!C: \ Users \ PranayKumar \ AppData \ Roaming \ npm-cache_logs \ 2018-09-22T18_07_48_781Z-debug.log

Ниже приведены мои файлы.

package.json

  "scripts": {
    "start": "pm2 start ./pm2-prod.json",
    "build": "mkdir build && babel src/server/ -d build/server --ignore ./src/server/server-entry.js",
    "server": "pm2 start ./pm2-dev.json --no-daemon",
    "build-webpack": "webpack --config webpack.config.client.js",
    "client": "webpack-dev-server --config webpack.config.client.js --open"
  },
  "devDependencies": {
    "@babel/core": "^7.1.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-proposal-json-strings": "^7.0.0",
    "@babel/plugin-proposal-numeric-separator": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5"
  }

server-side.babelrc

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "node": "current"
                }
            }
        ]
    ],
    "plugins": [
        "@babel/plugin-proposal-object-rest-spread"
    ]
}

server-entry.js

require('@babel/register');
require('./server.js');

1 Ответ

0 голосов
/ 22 сентября 2018

Как показано в трассировке стека, Babel вызывается через babel-cli, что является проблемой, поскольку babel-cli является CLI Babel 6.x.У вас также нет babel-cli в вашем списке devDependencies.

Для Babel 7 вам необходимо:

  • установить @babel/cli
  • и удалить все установленные версии babel-cli, которые уже существуют
  • Убедитесь, что вы на самом деле компилируете свои файлы с помощью команды babel из локального проекта, а не глобальной версии.
...