React App:“模块解析失败:意外的令牌”

时间:2021-02-19 02:43:11

标签: javascript node.js reactjs webpack

我观看了 React.js 教程并遵循了每一步,但似乎我什至无法正确地迈出第一步。 教程是在 16:10 左右here

指令告诉我下载node.js/npm(我的版本是6.13.4),然后运行npm create-react-app (app name here)。我做到了,然后立即尝试运行 npm start。本教程这样做没有问题,但是当我这样做时,它给了我这个错误:

Failed to compile.

./src/index.js 1:57
Module parse failed: Unexpected token (1:57)
File was processed with these loaders:
 * ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> $RefreshRuntime$ = require('C:/Users/Jack/Documents/Jack's Workshop/Coding/react/amogus2/node_modules/react-refresh/runtime.js');
| $RefreshSetup$(module.id);

请原谅我的无知,但我不知道从哪里开始寻找这个错误,因为我没有做任何事情来修改通过 create-react-app 自动给我的模板。

我尝试在网上四处寻找解决方案,发现了一个我应该称之为“webpack.config.js”的东西,但它既不在根文件中也不在 ./src 文件中。我在整个项目中搜索了这个名字,发现了几种这个配置文件的类型。我认为最有可能的是 node_modules/react-scripts/config/webpack.config.js

我该怎么做才能摆脱这个错误?提前致谢!

2 个答案:

答案 0 :(得分:0)

将 package.json 中的 "react-scripts": "4.0.3" 更改为 "react-scripts": "4.0.1"

参考:https://github.com/facebook/create-react-app/issues/10518#issuecomment-775476713

答案 1 :(得分:-1)

已修复!感谢 akhil choudhary 先生。

修复方法是将给定的 package.json 文件替换为 this,您就可以开始了!