"sh: 1: react-scripts: not found" In Docker - reactjs

I have a Docker container that fails to do a npm install for a react.js app that is cloned in the container when it is built. Would anybody know how to resolve the issue?
Error:
sh: 1: react-scripts: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! myrideweb#0.1.0 build: `react-scripts build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the myrideweb#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-06-19T04_00_09_065Z-debug.log
Dockerfile:
FROM ubuntu
Run apt-get update
Run apt-get install curl -y
Run curl -sL https://deb.nodesource.com/setup_10.x
Run apt-get install -y nodejs
Run apt-get install -y git
Run apt-get install npm -y
Run apt-get update -y
Run git clone https://github.com/sdrafahl/TerraWeb.git
WORKDIR /TerraWeb
Run npm install -g --save npm#latest
...

I have a similar issue and I managed to work around by changing:
"start: "react-scripts start"
to:
"start: "./node_modules/.bin/react-scripts start"
in the scripts section package.json.
I use the classic node base image but it should work more or less the same.
And I am still investigating why NPM is not able to resolve react-scripts when running inside Docker, any further help is very welcome :-)

This happened to me when 'react-scripts' was listed under the 'devDependencies' in the package.json file. Moving it to the "dependencies" section solved the issue.

Deleting package-lock.json and re-installing packages with npm install before building the container solved the issue for me.

I had this issue with react-scripts#4.0.1. I uninstalled and re-installed and that seemed to do the trick.
npm uninstall react-scripts
npm install -D react-scripts

Ok, I just managed to solve this problem in few simple steps, and i hope these instructions will help you too.
I run a docker with Ubuntu on Windows 10, and I share the node_modules folder by volume if this sounds familiar to you, so I believe this solution will help you.
Accidentally I installed the node modules from my Windows user, and that what cause the whole permissions problems.
So what I did is to delete the node_modules directory.
Then I installed the node modules from the Ubuntu Terminal, run npm install.
You may have to install npm on your Ubuntu, I downloaded the nvm installation file with curl with those instructions, How to install node on WSL for Linux, and then you may run npm install and then the react script will be able to run.
After you run npm install from Ubuntu, build and run your dockers.

I had this same problem recently and I was able to solve it, however, I don't like the solution very much but I think it's OK since it should run in Docker or in you local machine. That being said, my suggestion is to update the package.json with the following:
{
"scripts": {
"start": "$(npm bin)/react-scripts start",
}
}
npm-bin docs

Related

Why am I getting a 'cross-device link not permitted' error in Docker on Gitlab CI/CD pipeline?

I tried deleting the node_modules folder, but I'm still getting the error. It was working fine, but suddenly has started throwing this error.
It's a react app, if that helps.
Docker file
## Stage 0, "builder", based on Node.js, to build and compile the frontend
# base image
FROM node:alpine as builder
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
## add app
COPY . /app
# delete node modules to fix discrepancies
RUN rm -rf node_modules/
#RUN npm install && npm audit fix && npm audit fix --force && npm install
RUN npm install -g npm#7.0.3 && npm install && npm audit fix
RUN npm run build
## Stage 1, "deployer", use nginx to deploy the code
## start app
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /app/build /usr/share/nginx/html/
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf
console errors
npm notice
npm notice New patch version of npm available! 7.0.2 -> 7.0.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
npm notice Run `npm install -g npm#7.0.3` to update!
npm notice
npm ERR! code EXDEV
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -18
npm ERR! EXDEV: cross-device link not permitted, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-10-23T16_47_42_554Z-debug.log
The command '/bin/sh -c npm install -g npm#7.0.3 && npm install && npm audit fix' returned a non-zero code: 238
I ran into the same issue. Since your base image is node, npm should already be globally installed. There is no need to run npm install -g npm#7.0.3 and still be able to execute all npm related items afterwards.
Sorry, not enough rep to comment.
I actually ran into similar issues as well. Node's been updated which has bumped the npm version up to 7+, which seems to be causing people issues. My solution until I can fully flesh out the issues has been to version lock my Node/NPM within my container build.
FROM node:14.14-alpine3.11 is the instruction I'm using, keeps me at some 6.x.x version to keep my builds working.

npm start suddenly stops working on react app

I've been learning react for about two weeks, when suddenly npm start won't run. This is what I get instead:
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! recipe-app#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the recipe-app#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! /Users/Michelle/.npm/_logs/2020-07-29T14_35_20_988Z-debug.log
After a ton of googling I tried
npm install -g npm#latest but the permission was denied.
Deleted and reinstalled node several times, tried using Homebrew, etc, but nothing worked.
Edit: Found the solution!
Npm couldn't find react-scripts, so I had to change the scripts in package.json to
"start": "node_modules/react-scripts/bin/react-scripts.js start".
You need to install react-scripts
npm install react-scripts
The first line of the logs you just sent indicates your computer doesn't know the command react-scripts.
It means you need to install it.
When you use the -g option with npm install, it means you want to install globally the package, setting the package accessible for every user on your computer. That's why you have a permission error. You can solve this by adding sudo before the command maybe or running it with a elevated user.
It's not mandatory to install the package globally.
I suppose your package.json file contains a script named start starting with react-scripts.
If you install the react-scripts package with npm install react-scripts, you'll find the binary under node_modules/.bin/react-scripts.
Then you can replace in your start script configuration react-scripts with ./node_modules/.bin/react-scripts.
An example of a package.json file:
{
"name": "myapp",
"version": "1.0.0",
...
"scripts": {
...
"start": "./node_modules/.bin/react-scripts [...]",
...
},
...
}
running "npm install react-scripts" even if I had before, worked for me

create-react-app : npm ERR! Unexpected end of JSON input while parsing near '....'

Describe the bug
npx create-react-app my-app doesn't work for me
i tried npm cache clean --force but i get the same error again and again
Steps to reproduce
npm cache clean --force
npm / npx create-react-app front
npm init react-app front
npx: installed 98 in 37.068s
Creating a new React app in /home/h4kst3r/Desktop/APIs/restaurant-API/front.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
npm ERR! Unexpected end of JSON input while parsing near '...zAJNgZjZUkJ08ybAxwNnR'
npm ERR! A complete log of this run can be found in:
npm ERR! /home/h4kst3r/.npm/_logs/2020-05-20T20_47_49_189Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting front/ from /home/h4kst3r/Desktop/APIs/restaurant-API
Done.
System:
OS: Linux 5.4 Ubuntu 20.04 LTS (Focal Fossa)
Its happened because of slow internet . So wait till ur internet connection is normal. Or install all dependencies one by one
.
If npx create-react-app my-app command not working and throws an error like: npm ERR! Unexpected end of JSON input while parsing near '...zAJNgZjZUkJ08ybAxwNnR', Just check your npm version:
npm --version
npm -v
and if required update it:
npm install -g npm#latest
It will definitely work.
First check for npm version by running the following command npm --version. if you have an npm version then try instally npx globally with the help of npm i -g npx. if npm and ngx are installed properlly then this will work .
sudo npm i -g npx --force worked for me.
You should do it as a root user. Open your terminal and type sudo -i or sudo -s. After successful login, the $ prompt would change to # to indicate that you logged in as a root user on Ubuntu. Then if you use `create-react-app it should actually work :)
There are probably two things that can be at fault.
Poor internet connection.
outdated npm version.
update your npm and seek a strong internet connection.

create-react-app - react-scripts: command not found

i've just started out with react on codepen, and I really enjoy it! I decided to install it on my MacBook Air. I installed create-react-app using npm, and everything looked good. I then started a project, and everything went smoothly. When I ran npm start, I got an error:
sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! react-app#0.1.0 start: 'react-scripts start'
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I've come to the conclusion that npm can't find react-scripts. I have done almost everything I have come up with: I have updated npm; I have reinstalled the modules; I have started a new project, but I still get the same error. I've checked, react-scripts is in my node_modules file. The only thing I haven't done is install react-scripts globally, but the creator of create-react-app has said that that is a very bad idea. What should i do?
Just solved the problem:
In package.json, I changed "start": react-scripts start", to "start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start". This solved the problem.
Try running npm install before running npm start, if that doesn't work check out this article on the same issue - sh: react-scripts: command not found after running npm start
Adding the entire path also worked for me:
"start": "node_modules/react-scripts/bin/react-scripts.js start"
instead of just:
"start": "react-scripts start".
I wish I knew why this behavior changed in my pc.
Coincidence or not, I updated my xcode today.
delete package-lock.json:
sudo rm package-lock.json
delete node_modules:
sudo rm -rf node_modules
optionally upgrade npm:
sudo npm install -g npm
and install project again
npm i
run project:
npm start
worked for me in the situation like you described

react-scripts: command not found

I am currently trying to use create-react-app which uses three different packages: react, react-scripts and react-dom. I have installed create-react-app and then when I change into the directory and hit npm start I get a react-scripts: command not found. I've ran into a lot of problems with this. I can see react-scripts is in my node_modules folder but I keep getting command not found when trying to run npm start. I tried to delete and re-install all of my node_modules but it didn't work. Anyone else having this issue?
✘ ✝  Node/toDoApp/my-test   master±  npm start
> my-test#0.1.0 start /Users/jzilch/Desktop/Web
Projects/Node:Express/Node/toDoApp/my-test
> react-scripts start
sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-test#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-test#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
Firstly Delete package-lock.json file in your project folder.
And then install dependencies again by npm install. That should solve this issue.
Delete the /node_modules directory and the package-lock.json file using the rm command:
rm -rf node_modules
rm -rf package-lock.json
Install react-scripts using the following command:
npm install react-scripts
Install the dependencies using the following command:
npm install
Start the local server by running the following command:
npm run start
Note: If you are a Linux user then don't forget to add the sudo command before npm.
This usually happens because of a bad npm packages installation (using npm and yarn at the same time?). It can be desperating, but if you try these steps, it should work.
1st solution:
Remove node_modules folder. At the project's root folder, run
> yarn
> yarn run start
2nd solution:
At the project's root folder, run
> yarn upgrade
> yarn
> yarn run start
Next time you want to add a dependency using create-react-app, I recommend you to use 'yarn add' instead of 'npm install'.
(Source: https://github.com/facebook/create-react-app/issues/1155)
I use this in a dockerizer enviroment.
I already install locally in node_modules using package.json.
so, I added this:
RUN npm install -g react-scripts
RUN npm install
That solved my confusing issue
One option is to install the react-scripts package globally using the -g flag. This will make the command available to node, regardless of the working directory.
This command will install react-scripts globally:
npm install -g react-scripts
As I was using yarn, I had to run yarn add react-scripts.
I had this problem for ages and I eventually found my solution by sheer chance.
Turns out, you can't have spaces in any folder names.
e.g.
~/projects/tutorial/ReactJS/JavaScript Framework: ReactJS/app-name
won't work because JavaScript Framework: ReactJS contains spaces.
In general, it's probably not great practice to be using spaces in folder/file names anyway but I hope this saves someone at least 4 hours of trial and error.
I would recommend removing the : from your folder names too! (just to be safe)
i too faced this problem once .to solve this ,delete your
node_modules
yarn.lock
manifest_lock.json
it works .
I fixed it by changing folder name in my local system, from
new/landing
to
new_landing
However, the git branch name remains like "new/landing". This was the case with my MAC system.
For me, I deleted the project and initialized another one with the npm create-react-app <Folder Name> script. Instead of create-react-app <Folder Name>.
It worked for me.

Resources