Node.js app runs locally but fails on docker (sh: 1: rimraf: not found) - node.js

I am able to build the docker image but can't get the container to run. Here is the package.json:
{
"name": "linked-versions-viewer",
"version": "1.0.0",
"description": "...",
"main": "./dist/bundle.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist",
"build_only": "rollup -c",
"build": "cross-env NODE_ENV=production npm run clean && npm run build_only",
"serve": "parcel src/index.html --port 12345",
"start": "npm run clean && npm run serve"
},
"repository": {
"type": "git",
"url": "..."
},
"author": "...",
"license": "...",
"dependencies": {
"antd": "^4.12.3",
"base-widget": "...",
"react": "^17.0.2",
"react-dom": "^17.0.1"
},
"devDependencies": {
"#types/node": "^14.14.28",
"#types/react": "^17.0.2",
"#types/react-dom": "^17.0.1",
"cross-env": "^7.0.3",
"parcel-bundler": "^1.12.4",
"rev-hash": "^3.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.39.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-uglify": "^6.0.4",
"typescript": "^4.1.5"
}
}
Here is the dockerfile:
FROM node:14.17.0 as base
ENV NODE_ENV=production
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
FROM base as production
ENV NODE_PATH=./build
CMD ["npm", "start"]
I created the image by running docker build -t testapp . and tried running the container with docker run -p 8080:8080 -d testapp but it keeps immediately exiting with code 1. This is the error log for the image:
> linked-versions-viewer#1.0.0 start /app
> npm run clean && npm run serve
> linked-versions-viewer#1.0.0 clean /app
> rimraf dist
sh: 1: rimraf: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! linked-versions-viewer#1.0.0 clean: `rimraf dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the linked-versions-viewer#1.0.0 clean 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! /root/.npm/_logs/2021-06-09T20_40_17_204Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! linked-versions-viewer#1.0.0 start: `npm run clean && npm run serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the linked-versions-viewer#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I tried just removing the rimraf dependency altogether but then got a similar error for the parcel dependency, so maybe the packages aren't being installed properly? The app is also written in typescript if that's helpful.
Not sure what to try next. Thank you for any suggestions.

Form npm install docs,
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies
Since you have ENV NODE_ENV=production in your base image, neither rimraf nor parcel-bundler is installed inside your container.
Your npm start command is running npm run clean && npm run serve. npm run clean uses rimraf module and npm run serve uses parcel-bundler module. This is the reason why you're seeing both the errors.
You can try one of the following solutions,
Remove ENV NODE_ENV=production from your Dockerfile (This is the quickest solution but should not be used in production)
You can install rimraf and parcel-bundler globally inside the container using:
RUN npm install --global rimraf && npm install --global parcel-bundler
However, I still don't think this is a good production-ready setup.
You can properly build your app using npm run build inside your container and serve it. However, I am not familiar with React enough to help you set up this on Docker.

Related

sh: 1: del: not found

I'm wondering if you can help me
Failed Heroku deploy. Been looking at other similar stack overflow posts and changing package.json file trying solutions that have worked for others with no luck. I don't think this is a port issue but it could be a package.json issue or something completely different. Any help, tips or advice is greatly appreciated!
Heroku Log:
-----> Build
Running build
> honeyman-designs#1.0.0 build /tmp/build_a9c0d0bf
> del dist && babel backend -d dist && cd frontend && npm install && npm run build
sh: 1: del: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! honeyman-designs#1.0.0 build: `del dist && babel backend -d dist && cd frontend && npm
install && npm run build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the honeyman-designs#1.0.0 build 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! /tmp/npmcache.tyCCY/_logs/2020-12-31T15_09_59_938Z-debug.log
This is my package.json file:
{
"name": "honeyman-designs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.10.15",
"react-paypal-button-v2": "^2.6.2"
},
"devDependencies": {
"#babel/cli": "^7.12.1",
"#babel/core": "^7.12.3",
"#babel/node": "^7.12.1",
"#babel/preset-env": "^7.12.1",
"nodemon": "^2.0.6"
},
"scripts": {
"start": "nodemon --watch backend --exec babel-node backend/server.js",
"build": "rd /s dist && babel backend -d dist && cd frontend && npm install && npm run build",
"heroku-postbuild-x": "npm run build && cd frontend && npm install && npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codegreene93/HoneymanDesigns.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/codegreene93/HoneymanDesigns/issues"
},
"homepage": "https://github.com/codegreene93/HoneymanDesigns#readme",
"engines": {
"node": "12.4.0",
"npm": "6.14.10"
}
}
I have tried clearing cache and deleting and reinstalling node_modules and package-lock.json
I've updated the node and npm version
I'm using Windows 10 and I've also tried it like this:
del dist && babel backend -d dist && cd frontend && npm install && npm run build
rd /s dist && babel backend -d dist && cd frontend && npm install && npm run build
rm -r dist && babel backend -d dist && cd frontend && npm install && npm run build
None of them run get the same sh:1 error
server.js file:
app.listen(config.PORT, () => {
console.log('Server started at http://localhost:5000');
});
config.js
PORT: process.env.PORT || 5001
rd and del are Windows commands, but Heroku doesn't run Windows. You won't be able to use those commands on Heroku.
I suggest using a cross-platform alternative like rimraf insted of platform-specific commands so your scripts will run properly on your local development environment as well as your hosted environment.
Add it to your dependencies and then use something like
npx rimraf dist && babel backend -d dist && cd frontend && npm install && npm run build

Using NPM for SCSS but the script will not watch for changes. It gives me a error

I have installed Node v12.10.0, NPM v6.10.3. I have also tried to install the node LTS version as well.
I built my project directory and inside the directory I ran "npm init" and after I ran "npm install --save-dev node-sass". Everything seems good up to this point.
my package.json file looks like this
{
"name": "dashboard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"scss": "node-sass --watch scss -o css"
},
"author": "",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.12.0"
}
}
After I go to run " npm run scss" then I receive this.
> dashboard#1.0.0 scss /Users/adakaitalker/Documents/school/dev/learning/2-september/4-week/9:13:19/dashboard
> node-sass --watch scss -o css
sh: node-sass: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! dashboard#1.0.0 scss: `node-sass --watch scss -o css`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the dashboard#1.0.0 scss 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/adakaitalker/.npm/_logs/2019-09-13T22_43_56_711Z-debug.log
figured it out. I installed homebrew and linked it to node then I used homebrew to uninstall it and reinstall it and it works now.

'.' is not recognized as an internal or external command (when running npm install for firebaseUI)

I cannot install npm packages on my firebaseUI demo application.
I cloned the master branch on github and am simply trying to run "npm install" but I am getting an error I have never come across with node package manager. I get
'.' is not recognized as an internal or external command
I also tried this will cygwin64 and had the exact same result. below is the error, and below that is my package.json
firebaseui#3.3.0 generate-test-files C:\repos\Firebase Demos\firebaseui-web
> ./buildtools/generate_test_files.sh
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! firebaseui#3.3.0 generate-test-files: `./buildtools/generate_test_files.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the firebaseui#3.3.0 generate-test-files 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\adam\AppData\Roaming\npm-cache\_logs\2018-08-18T01_43_27_526Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! firebaseui#3.3.0 test: `npm run build && npm run generate-test-files && ./buildtools/run_tests.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the firebaseui#3.3.0 test 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\adam\AppData\Roaming\npm-cache\_logs\2018-08-18T01_43_27_547Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! firebaseui#3.3.0 prepublish: `npm run test && cp -r dist demo/public`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the firebaseui#3.3.0 prepublish 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\adam\AppData\Roaming\npm-cache\_logs\2018-08-18T01_43_27_577Z-debug.log
package.json
{
"name": "firebaseui",
"version": "3.3.0",
"description": "Javascript library for customizable UI on top of Firebase SDK",
"files": [
"dist/firebaseui.js",
"dist/firebaseui.css",
"dist/npm.js",
"dist/index.d.ts",
"dist/externs",
"LICENSE",
"README.md",
"package.json"
],
"main": "./dist/npm.js",
"types": "./dist/index.d.ts",
"style": "dist/firebaseui.css",
"scripts": {
"build": "gulp",
"build-all": "gulp build-all",
"build-soy": "gulp build-soy",
"demo": "npm run build && ./buildtools/run_demo.sh",
"test": "npm run build && npm run generate-test-files && ./buildtools/run_tests.sh",
"serve": "npm run build && npm run generate-test-files && gulp serve",
"generate-test-files": "./buildtools/generate_test_files.sh",
"prepublish": "npm run test && cp -r dist demo/public"
},
"test": "npm run test",
"author": "Google",
"repository": {
"type": "git",
"url": "https://github.com/firebase/firebaseui-web.git"
},
"license": "Apache-2.0",
"devDependencies": {
"closure-builder": "^2.2.34",
"firebase": "^5.0.0",
"firebase-tools": "^4.0.1",
"fs-extra": "^3.0.1",
"google-closure-compiler": "^20171112.0.0",
"google-closure-library": "^20171112.0.0",
"google-closure-templates": "^20150410.0.0",
"gulp": "^4.0.0",
"gulp-clean-css": "^2.0.12",
"gulp-closure-compiler": "^0.4.0",
"gulp-concat-css": "^3.1.0",
"gulp-connect": "^5.5.0",
"gulp-css-flip": "^0.4.0",
"gulp-css-inline-images": "^0.1.1",
"gulp-sass": "^2.3.2",
"gulp-util": "^3.0.7",
"material-design-lite": "^1.2.0",
"protractor": "^5.3.2",
"streamqueue": "^1.1.1"
},
"dependencies": {
"dialog-polyfill": "^0.4.7"
},
"peerDependencies": {
"firebase": ">=5.0.0"
}
}
Although this question is old I ran into the same problem when I was collaborating with another developer using another OS (Linux x Windows).
At the beginning of the project a script .sh was failing depending on the OS. We had to constantly modify the json file after merging some branch.
The solution we came up with was to append the shell being used to call the script, e.g. we changed the initialization script to
...
{
start: bash ./myscript && npm run start
}
...
It works fine on Linux and on Gitbash on Windows.
> ./buildtools/generate_test_files.sh
here just leave out dot-slash(./)
Though, if you wanted to, you could use .\\ (since single '\' would skip the next character) and it would work.

react-scripts: not found on create-react-app project on ubuntu?

I am working on reactjs using this one
https://github.com/facebookincubator/create-react-app
But when i deploy it to digitalocean on top of ubuntu 16
I can not run npm run build and got this as an error.
deploy#xxxx:/www/tmdb_admin$ sudo npm run build
[sudo] password for deploy:
> tmdb_admin#0.1.0 build /www/tmdb_admin
> react-scripts build
sh: 1: react-scripts: not found
npm ERR! Linux 4.4.0-57-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
npm ERR! node v7.3.0
npm ERR! npm v4.0.5
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! tmdb_admin#0.1.0 build: `react-scripts build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the tmdb_admin#0.1.0 build script 'react-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the tmdb_admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! react-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs tmdb_admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls tmdb_admin
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /www/tmdb_admin/npm-debug.log
So this is my package.json file.
{
"name": "tmdb_admin",
"version": "0.1.0",
"private": true,
"devDependencies": {
"autoprefixer-stylus": "0.10.0",
"concurrently": "3.0.0",
"react-scripts": "0.6.1",
"stylus": "0.54.5"
},
"dependencies": {
"bulma": "^0.2.3",
"case-sensitive-paths-webpack-plugin": "^1.1.4",
"es6-promise": "^4.0.5",
"font-awesome": "^4.7.0",
"isomorphic-fetch": "^2.2.1",
"jwt-simple": "^0.5.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-pagify": "^2.1.1",
"react-redux": "^4.4.5",
"react-router": "^2.4.0",
"react-router-redux": "^4.0.4",
"react-slick": "^0.14.5",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
"segmentize": "^0.4.1",
"slick-carousel": "^1.6.0"
},
"scripts": {
"start": "react-scripts start",
"watch": "concurrently --names 'webpack, stylus' --prefix name 'npm run start' 'npm run styles:watch'",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"styles": "stylus -u autoprefixer-stylus ./src/css/style.styl -o ./src/css/style.css",
"styles:watch": "stylus -u autoprefixer-stylus -w ./src/css/style.styl -o ./src/css/style.css"
}
}
And this is my node and npm version.
deploy#xxxx:~$ node -v
v7.3.0
deploy#xxxx:~$ npm -v
4.0.5
How can i fix this and make npm run build works?
Thanks!
I had the same problem today and I fixed it running install again.
All that you need to do is rum again the command npm install into your project so you'll be able to run npm start comand again!
Works for me!
I hope I've Helped!
When you copy a generated create-react-app project to another directory (i.e. when it was deployed to the server), it failed because symlinks were not preserved. See https://github.com/facebookincubator/create-react-app/issues/200. The file react-scripts in ./node_modules/.bin/ needs to be symlinked to ./node_modules/react-scripts/bin/react-scripts.js. Using diff will not show the differences since the symlinks will be resolved.
Easiest solution is to create a temporary react project on the server (i.e. on the Digitalocean) and then copy the content of the ./node_modules/.bin using copy -a (and not copy -r, in order to preserve symlinks).
$ create-react-app tempReact
$ cp -a tempReact/node_modules/.bin/* myActualReactApp/node_modules/.bin
Another solution is to manually re-create the symlinks.
$ ln -s myActualreactApp/node_modules/react-scripts/bin/react-scripts.js myActualReactApp/node_modules/.bin/react-scripts
Run:
sudo chown -R $USER:$USER '/home/ubuntu/.npm/'
On Linux OS NPM and NodeJS are installed globally with sudo and the owner of that files is the root and usually a user can only read/execute that packages. When NPM is stalled a ~/.npm/ folder is created by the root. By running create-react-app you are executing the command as user and create-react-app is trying to modify something in the ~/.npm/ directory which is owned by the root and not to current user. You need to change the owner of that directory to you, so you can modify it without sudo privileges.
Often similar thing happens when you install NPM package with sudo e.g. sudo npm install --save. Again the newly installed package in owned by the root and for example when you try to update/modufy/delete your project without sudo infrnt of NPM you will have similar permission error. In these cases navigate to your project directory and change its owner by running:
sudo chown -R $USER:$USER
Source: create-react-app fails with permission denied

Angular 2 QuickStart on Linux not working

I'm setting up Angular 2 Quick Start Tutorial from scratch on a virtualbox Linux machine build. I've followed all the instructions as part of the 5 minute quick start but when I get to the "npm start" I get this error:
/media/sf_testdev/angular-quickstart$ npm start
> angular-quickstart#1.0.0 start /media/sf_testdev/angular-quickstart
> tsc && concurrently "npm run tsc:w" "npm run lite"
sh: 1: concurrently: not found
npm ERR! Linux 4.4.0-42-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v6.7.0
npm ERR! npm v3.10.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! angular-quickstart#1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the angular-quickstart#1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular-quickstart
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /media/sf_testdev/angular-quickstart/npm-debug.log
Here is my current package.json file
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"#angular/common": "2.0.0-rc.6",
"#angular/compiler": "2.0.0-rc.6",
"#angular/compiler-cli": "0.6.0",
"#angular/core": "2.0.0-rc.6",
"#angular/forms": "2.0.0-rc.6",
"#angular/http": "2.0.0-rc.6",
"#angular/platform-browser": "2.0.0-rc.6",
"#angular/platform-browser-dynamic": "2.0.0-rc.6",
"#angular/router": "3.0.0-rc.2",
"#angular/upgrade": "2.0.0-rc.6",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.11",
"systemjs": "0.19.27",
"zone.js": "^0.6.17",
"angular2-in-memory-web-api": "0.0.18",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^1.8.10",
"typings":"^1.3.2"
}
}
Nothing I have tried online seems to work to fix. thanks for the help in advance!
It seems the error is when it tries to run the command concurrently
sh: 1: concurrently: not found
you have to run npm install first to install the dependencies and then you will have concurrently, and everything should work fine.
That's because tsc command finds errors in the code. If you execute only tsc in terminal can you see the errors and fix it.
If you only run the app remove tsc && in start line, finally this is as:
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\",
to
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
With it works.
Sorry I did dont see all the log, concurrently: not found is because concurrently module isn't install, deleting node_modules folder and executing:
npm install
Or installing specifically concurrently with:
npm install -g concurrently

Resources