【发布时间】:2020-02-24 15:16:14
【问题描述】:
Github 代码链接:https://github.com/bhatvikrant/IndecisionApp
我已经运行了 npm i,然后完成了 yarn run dev-server,我使用了 webpack。 我在 MacOs 机器上。 我也制作了 .babelrc 文件。
运行yarn run dev-server后出现的错误:
VIKRANTs-MacBook-Pro:IndecisionAPP VIKRANT$ yarn run dev-server
yarn run v1.19.1
$ webpack-dev-server
Project is running at http://localhost:8080/
webpack output is served from /
Content not from webpack is served from /Users/VIKRANT/Desktop/IndecisionAPP/public
Hash: 35d055107a6a0062196d
Version: webpack 3.1.0
Time: 1305ms
Asset Size Chunks Chunk Names
bundle.js 867 kB 0 [emitted] [big] main
[35] multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.js 40 bytes {0} [built]
[36] (webpack)-dev-server/client?http://localhost:8080 5.59 kB {0} [built]
[37] ./node_modules/url/url.js 23.3 kB {0} [built]
[38] ./node_modules/node-libs-browser/node_modules/punycode/punycode.js 14.7 kB {0} [built]
[39] ./node_modules/url/util.js 314 bytes {0} [built]
[40] ./node_modules/querystring-es3/index.js 127 bytes {0} [built]
[43] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
[44] ./node_modules/ansi-regex/index.js 135 bytes {0} [built]
[45] (webpack)-dev-server/client/socket.js 856 bytes {0} [built]
[46] ./node_modules/sockjs-client/lib/entry.js 244 bytes {0} [built]
[77] (webpack)-dev-server/client/overlay.js 3.6 kB {0} [built]
[78] ./node_modules/ansi-html/index.js 4.26 kB {0} [built]
[79] ./node_modules/html-entities/index.js 231 bytes {0} [built]
[82] (webpack)/hot/emitter.js 77 bytes {0} [built]
[84] ./src/app.js 2.33 kB {0} [built] [failed] [1 error]
+ 70 hidden modules
ERROR in ./src/app.js
Module build failed: Error: Requires Babel "^7.0.0-0", but was loaded with "6.25.0". 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 vers
ion. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "b
abel-core" to see what is calling Babel. (While processing preset: "/Users/VIKRANT/Desktop/IndecisionAPP/node_m
odules/@babel/preset-env/lib/index.js")
at throwVersionError (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/@babel/helper-plugin-utils/lib/inde
x.js:65:11)
at Object.assertVersion (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/@babel/helper-plugin-utils/lib/i
ndex.js:13:11)
at /Users/VIKRANT/Desktop/IndecisionAPP/node_modules/@babel/preset-env/lib/index.js:177:7
at /Users/VIKRANT/Desktop/IndecisionAPP/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at /Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/options/option-mana
ger.js:317:46
at Array.map (<anonymous>)
at OptionManager.resolvePresets (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-loader/lib/index.js:49:20)
at Object.module.exports (/Users/VIKRANT/Desktop/IndecisionAPP/node_modules/babel-loader/lib/index.js:174:20)
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.js
webpack: Failed to compile.
请帮我纠正这个语法错误,我已经花了将近一天的时间来解决这个问题。
【问题讨论】:
-
Requires Babel "^7.0.0-0" 更改 babel 版本并使用 instal npm 命令重新安装 npm。
-
@AyushiKeshri 你能指定命令吗,真的很有帮助,谢谢
-
Yarn 不是“更好的做法”。
-
@VikrantBhat 下面的用户 Jim G. 仔细检查了下面的 package.json 修改。看起来它应该可以解决您的问题。基本上你的开发版本和依赖版本不匹配因此错误。
-
真的推荐你read and learn 包/依赖是如何工作的。
标签: javascript reactjs npm webpack babeljs