简体   繁体   中英

React App: "Module parse failed: Unexpected token"

I watched a React.js tutorial and followed through every step, but it seems like I can't even get the first step right. The tutorial is here around the 16:10 mark.

The instructions told me to download node.js / npm (my version is 6.13.4), and then run npm create-react-app (app name here) . I did it, and then right away tries to run npm start . The tutorial had no trouble doing so, but when I did it, it gave me this error:

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);

Forgive me for my ignorance, but I have no idea where to start looking for this error, because I have not done a single thing to modify the template automatically given to me through create-react-app .

I tried looking around online for solutions, and found a thing I'm supposed to have called "webpack.config.js", yet it is neither in the root file nor in the./src file. I searched for the name in the entire project and found several types of this config file. I thought the most probably one is in node_modules/react-scripts/config/webpack.config.js .

What do I do to get rid of this error? Thanks in advance!

change "react-scripts": "4.0.3" to "react-scripts": "4.0.1" in package.json

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

Scrolling through the link posted by @finiteEffort, I came across this comment:

@fabiangamboa95 This is only a guess, but I see that the path with aws's has a single quote in it.

#10964 also has a single quote in the path with a similar error.

So run pwd in the root folder of your app. If the path contains a single quote, then you will get this error in > 4.0.1 until the team fixes the issue.

FIXED! Thanks to mister akhil choudhary .

The fix was to replace the given package.json file with this , and you're good to go!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM