问题
After running the install script, the server starts and serves a page displaying the same text after the 'Failed to compile line.'
I'm running Windows 10 and auto update just updated my pc today, right before I did the create-react-express install.
PS H:\mern-passport> npm start
> mern@1.0.0 start H:\mern-passport
> if-env NODE_ENV=production && npm run start:prod || npm run start:dev
> mern@1.0.0 start:dev H:\mern-passport
> concurrently "nodemon --ignore 'client/*'" "npm run client"
[0] [nodemon] 1.19.4
[0] [nodemon] to restart at any time, enter `rs`
[0] [nodemon] watching dir(s): *.*
[0] [nodemon] watching extensions: js,mjs,json
[0] [nodemon] starting `node server.js`
[0] API server now on port 3001!
[1]
[1] > mern@1.0.0 client H:\mern-passport
[1] > cd client && npm run start
[1]
[1]
[1] > mern@0.1.0 start H:\mern-passport\client
[1] > react-scripts start
[1]
[1] Starting the development server...
[1]
[1] Failed to compile.
[1]
[1] ./src/index.css (./node_modules/css-loader??ref--6-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
[1] Error: Package exports for 'H:\mern-passport\client\node_modules\autoprefixer\node_modules\kleur' do not define a valid './colors' target
[0] Error: ENOENT: no such file or directory, stat 'H:\mern-passport\client\build\index.html'
[0] Error: ENOENT: no such file or directory, stat 'H:\mern-passport\client\build\index.html'
回答1:
Seems to be an issue with autoprefixer latest version. I refereed https://github.com/postcss/autoprefixer/issues/1328 and tried downgrading autoprefixer in my project and it works now. Try:
npm install autoprefixer@9.8.0
Happy coding!
回答2:
I was running into this issue too. I installed yarn and created a new project with the npx create-react-app
command and this fixed the issue.
回答3:
I also faced this problem. And it looks like a problem with autoprefixer version, so i changed the version.
npm install autoprefixer@9.8.0
I tried this, and it works perfectly.
来源:https://stackoverflow.com/questions/62481678/react-app-failed-to-compile-after-install