想通过babel-node让后端node可以运行es6,结果装完babel-cli总是报错Requires Babel "^7.0.0-0", but was loaded with "6.26.3".具体如下:
error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
at throwVersionError (/Users/apple/HBuilderXProjects/travel-house/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
at Object.assertVersion (/Users/apple/HBuilderXProjects/travel-house/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
at _default (/Users/apple/HBuilderXProjects/travel-house/node_modules/@babel/plugin-proposal-decorators/lib/index.js:43:7)
at /Users/apple/HBuilderXProjects/travel-house/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at Function.memoisePluginContainer (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at compile (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/lib/node.js:103:45)
at loader (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/lib/node.js:144:14)
at Object.require.extensions.(anonymous function) [as .js] (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-register/lib/node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at Object.<anonymous> (/Users/apple/HBuilderXProjects/travel-house/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
我的package.json配置如下
"dependencies": {
"@babel/cli": "^7.2.3",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/runtime": "^7.2.0",
"@svgr/webpack": "2.4.1",
"antd": "^3.12.1",
"babel-cli": "^6.26.0",
"babel-eslint": "9.0.0",
"babel-jest": "^23.6.0",
"babel-loader": "8.0.4",
"babel-plugin-import": "^1.8.0",
"babel-plugin-named-asset-import": "^0.3.0",
"babel-preset-react-app": "^7.0.0",
"bfj": "6.1.1",
...
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-decorators": "^7.2.3",
"@babel/preset-env": "^7.2.3",
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-import": "^1.11.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"jest": "^23.6.0"
}
我已经折腾了好几个小时,网上能试的方法都尝试,依然是这个报错!求大神们救命!
把 node_modules 文件夹下的都删了,在重新 npm install 一下
另外,
"babel-cli": "^6.26.0"
这行是不是冲突了要看具体的版本号,可以去 package-lock.json, 或者如果你用了yarn,那就去 yarn-lock.json 中找。