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.
在构建容器之前删除package-lock.json
并使用npm install
重新安装包为我解决了这个问题。
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",
}
}
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
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.