I have been developing a React app with nodejs backend. Now I'm getting this error when I run npm run build. I have update node and npm to latest versions. I'm getting the following error log in the console.
$ npm run build
> client#0.1.0 build C:\Demos\mern-course\client
> react-scripts build
Creating an optimized production build...
Failed to compile.
./src/App.css
ReferenceError: loader is not defined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
My package.json is as follows.
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.4.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"bootstrap": "^4.4.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.2.0",
"react-scripts": "^3.4.0",
"react-transition-group": "^4.3.0",
"reactstrap": "^8.4.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"uuid": "^3.4.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Here is the link for github repo for the code.
./src/App.css
ReferenceError: loader is not defined
You need to check that you are importing App.css correctly. This should be in your App.js
Replace "css-loader" folder in front end node-modules folder with another "css-loader" which has taken from working react project.
Related
can someone tell me the problem with my Dockerfile , i tried build image react js with docker and somehow it always show error when step run npm install
dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package.json .
COPY package-lock.json .
#COPY . .
#RUN npm install -g npm#8.19.3
#RUN npm install react-scripts
#RUN npm ci
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "start"]
package.json
{
"name": "app-test",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.10.4",
"#emotion/styled": "^11.10.4",
"#fontsource/roboto": "^4.5.8",
"#mui/icons-material": "^5.10.9",
"#mui/material": "^5.10.8",
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"blueimp-md5": "^2.19.0",
"file-saver": "^2.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-excel-export": "^1.0.6",
"react-excel-renderer": "^1.1.0",
"react-redux": "^8.0.4",
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"sass": "^1.55.0",
"web-vitals": "^2.1.4",
"xlsx": "^0.18.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"homepage": ".",
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
and i have very very long package-lock.json
i tried to change npm install to npm install -g npm#8.19.3 from npm suggestion, and after i change dockerfile, it success build image, but when i tried to run container, it says
> app-test#0.1.0 start
> react-scripts start
sh: react-scripts: not found
can anyone tell me where am i wrong ?
I have downloaded a simple template from GitHub. When i tried to install npm install for node_modules it shows following errors.
npm ERR! code E404
npm ERR! 404 Object Not Found - GET https://skimdb.npmjs.com/yocto-queue/-/yocto-queue-0.1.0.tgz - not_found
npm ERR! 404
npm ERR! 404 'yocto-queue#https://skimdb.npmjs.com/yocto-queue/-/yocto-queue-0.1.0.tgz' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ali\AppData\Local\npm-cache\_logs\2022-01-24T15_02_47_113Z-debug.log
**
when i write npm start following errors are showing.
**
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'react'
Require stack:
C:\Users\Ali\AppData\Roaming\npm\node_modules\react-scripts\scripts\start.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.resolve (node:internal/modules/cjs/helpers:108:19)
at Object. (C:\Users\Ali\AppData\Roaming\npm\node_modules\react-scripts\scripts\start.js:43:31)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\Users\Ali\AppData\Roaming\npm\node_modules\react-scripts\scripts\start.js'
]
}
my package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"bootstrap": "^5.0.2",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"main": "index.js",
"author": "zain",
"license": "ISC",
"description": ""
}
I am trying to run my react-ebay-clone but the
npm start
command does not work. Instead react throws this error
freduah#freduah:~/react-ebay-clone/react-ebay-clone$ npm start
> react-ebay-clone#0.1.0 start /home/freduah/react-ebay-clone/react-ebay-clone
> react-scripts start
sh: 1: react-scripts: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! react-ebay-clone#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-ebay-clone#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/freduah/.npm/_logs/2020-10-26T19_24_02_415Z-debug.log
freduah#freduah:~/react-ebay-clone/react-ebay-clone$
Below Is My package.json file
{
"name": "react-ebay-clone",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I have found this previous stack overflow,
npm start error with create-react-app.
First of all, I would like to apologize for the spelling mistakes, I'm not very good.
I have a problem whilethe starting my mern server...
I want to run it with with "npm run dev". This command line execute "npm run server" and "npm run client".
Here's my errors :
C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04>npm run dev
mern_d04#1.0.0 dev C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04
concurrently "npm run server" "npm run client"
[0] Error occurred when executing command: npm run server
[0] Error: spawn cmd.exe ENOENT
[0] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[0] at onErrorNT (internal/child_process.js:467:16)
[0] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] Error occurred when executing command: npm run client
[1] Error: spawn cmd.exe ENOENT
[1] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[1] at onErrorNT (internal/child_process.js:467:16)
[1] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] npm run client exited with code -4058
[0] npm run server exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mern_d04#1.0.0 dev: `concurrently "npm run server" "npm run client"`>npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mern_d04#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Jérémy\AppData\Roaming\npm-cache\_logs\2020-04-22T19_45_03_286Z-debug.log
And Here's, my root package.json :
{
"name": "mern_d04",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"client-install": "npm-install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"concurrently": "^5.1.0",
"express": "^4.17.1",
"is-empty": "^1.2.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.10",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"validator": "^13.0.0"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}
And here's my client package.json :
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"classnames": "^2.2.6",
"jwt-decode": "^2.2.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I've tried many things and, the most surprising thing is : it works on the computer of my friend but not mines.
Please someone can help me? :)
EDIT : Node version : 13.0.0
EDIT : Found the solution. I "just" had a variable "C:\Windows\System32" in the environment variables :)
I was facing the same problem.
for this code works, you can try this.. on your root package.json
"scripts": {
"start": "node index",
"server": "nodemon index",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"cd client && npm start\""
},
and then from root directory type npm run dev
The node_modules are not compatible with your current systems. You may remove the node_modules folders at the root level AS WELL AS at the client level. Then you install both node_modules AGAIN.
I am trying to push my app to Heroku, but I am getting an error when it gets to the heroku postbuild script:
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote: audited 905058 packages in 15.807s
remote: found 0 vulnerabilities
remote:
remote:
remote: > client#0.1.0 build /tmp/build_b7466d5902dcde0a3dc95258046c08c6/client
remote: > react-scripts build
remote:
remote: sh: 1: react-scripts: Permission denied
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! client#0.1.0 build:react-scripts build
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the client#0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.CXg0t/_logs/2019-10-17T19_19_39_823Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! safety-influence#1.0.0 heroku-postbuild:NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the safety-influence#1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.CXg0t/_logs/2019-10-17T19_19_39_835Z-debug.log
Here is my package.json folder on the server side:
{
"name": "safety-influence",
"version": "1.0.0",
"description": "",
"engines": {
"node": "12.3.1"
},
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "David Jaenike",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"concurrently": "^4.1.2",
"express": "^4.17.1",
"gridfs-stream": "^1.1.1",
"is-empty": "^1.2.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.3",
"multer": "^1.4.2",
"multer-gridfs-storage": "^3.3.0",
"nodemon": "^1.19.3",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"validator": "^11.1.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
}
}
and on the client side:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"classnames": "^2.2.6",
"file-saver": "^2.0.2",
"jwt-decode": "^2.2.0",
"moment": "^2.24.0",
"react": "^16.10.1",
"react-app-polyfill": "^1.0.4",
"react-dom": "^16.10.1",
"react-redux": "^7.1.1",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.2.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
"sweetalert2": "^8.18.0",
"sweetalert2-react-content": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:80",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"react-social-icons": "^4.1.0"
}
}
I have tried running npm install on both the server and client side again, and have also deleted, the reinitialized the git repository. No luck. ANyone have any advice on how to get this build working?