sh: 1: del: not found - node.js

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

Related

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

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.

Gatsby’s Environmental Variables "env.cmd not found"

Trying to run env.cmd with Gatsby but I'm getting sh: env-cmd not found. I do have installed the package. I have tried deleting .node-modules and running npm install but I'm still getting the same error.
gatsby-config.js:
{
...
"scripts": {
"build": "gatsby build",
"develop": "env-cmd --file .env.development --fallback gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"gatsby": "^2.18.12",
"gatsby-plugin-sass": "^2.1.26",
"node-sass": "^4.13.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"typescript": "^3.7.4"
},
"devDependencies": {
"env-cmd": "^8.0.2",
"prettier": "^1.19.1"
},
...
}
Terminal:
npm run develop
> gatsby-starter-hello-world#0.1.0 develop /Users/renatognunes/Documents/Studies 1:4/Gatsby/gatsby-site
> env-cmd --file .env.development --fallback gatsby develop
sh: env-cmd: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! gatsby-starter-hello-world#0.1.0 develop: `env-cmd --file .env.development --fallback gatsby develop`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the gatsby-starter-hello-world#0.1.0 develop script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
UPDATE
For anyone else running into the same issue, here is the solution I found that worked for me: https://stackoverflow.com/a/56367980/10225590
Changing my npm version to v16.3.1 from v14.18.3 fixed this for me

ENOENT: no such file or directory when running npm install command

When I run npm install, I getting the following error,
npm WARN tar ENOENT: no such file or directory, open 'D:\Live Project\insyte-mobile\insyte-mobile\node_modules.staging\core-js-c9f4d03d\library\fn\symbol\unscopables.js'
Here is a screen shoot of the error
:
Here is my package.json
{
"name": "tonight-mobile",
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~27.0.0",
"react-test-renderer": "16.3.1"
},
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"eject": "expo eject",
"initial-android": "npm install && npm run android",
"initial-ios": "npm install && npm run ios",
"android": "expo start --android",
"ios": "expo start --ios",
"test": "jest",
"postinstall": "rm ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^32.0.0",
"expo-image-picker": "^5.0.2",
"firebase": "^5.7.1",
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.2.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-firebase": "^5.1.1",
"react-native-image-crop-picker": "^0.21.3",
"react-native-image-picker-form": "^0.2.5",
"react-native-maps": "^0.21.0",
"react-native-responsive-image": "^2.3.1",
"react-native-swiper": "^1.5.14",
"react-native-vector-icons": "^5.0.0",
"react-navigation": "^2.13.0",
"react-navigation-tabs": "^1.0.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-persist": "^5.10.0",
"redux-persist-filesystem-storage": "^1.3.2",
"redux-thunk": "^2.3.0",
"tcomb-form-native": "^0.6.20"
}
}
above is the package.json file.
I have also used another code of this project, but this time I'm getting following error :
First delete the package-lock.json and then try npm install
Delete node_modules folder and package-lock.json, then run npm install
All you need to do is
Open a terminal in your pc's root and run this command:
killall node
Before restart the new metro bundler please reinstall the dependencies on yarn or npm :
npm i OR yarn
Also the article: ENOENT: no such file
Follow this step:
Delete node_modules folder and package-lock.json file
Run this command:
npm cache clean -force
Then run this command:
npm install (if the issue is not yet fixed try the following 4th step.)
Run this command npm install -g npm,then npm install
Finally run this command: npm start
Please check your current working directory. if you have created project using
npx react-native init demo
then navigate inside project from terminal using
cd demo
npm install
will install all npm modules and you can also check installed packages in the directory: demo/node_modules
also if project is expo base then
run expo eject to eject from expo
Check the node version, if the application was build using an older node version then you can downgrade your local environment node version using NVM (node version manager).
My simple solution for this error:
"npm WARN tar ENOENT:no such file or directory
Not only for ENOENT if all files in npm modules shows this kinds of error.
Go to your command prompt
Check for npm version(npm -v)
If its giving a version then type command npm init and click on enter for whatever it asks
After completing all the steps and then again try to create one angular project. It will be created without any errors in node modules.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path E:\Projects\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'E:\Projects\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
Solution ==> Check the root directory you might be outside the root directory or in wrong folder path has been opened
I suspect you do not have git installed on your computer. This is particularly true if you are getting this error at the bottom of your log:
npm ERR! syscall spawn git
If so, then you need to install git from here: https://git-scm.com/downloads.
I had the same problem as you, and once I installed git, the problem went away.
Do you have a package.json file in the folder ?*
To run npm install you need to have a package.json file.

"." Is not a command or a bat When trying to serve project

So im currently building/working on a project on my win 10 machine, with nodeJS
But im running into a problem when running it. it says the following.
C:\Users\myuser\Documents\Gits\deon>npm start
> deon#1.0.0 start C:\Users\myuser\Documents\Gits\deon
> ./scripts/serve
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! deon#1.0.0 start: `./scripts/serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the deon#1.0.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! C:\Users\Melonendk\AppData\Roaming\npm-cache\_logs\2018-11-16T08_00_31_347Z-debug.log
I tried to check the system environment on windows as many others have posted on the internet but with no luck :(
How can I fix this problem?
Package.json
{
"name": "deon",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "./scripts/serve",
"start-prod": "./scripts/serve-bin",
"build": "./scripts/build",
"test": "echo \"Not implemented.\" && exit 1"
},
"author": "",
"contributors": [],
"license": "ISC",
"dependencies": {},
"devDependencies": {
"eslint": "^4.18.1"
}
}
My serve file.
#!/usr/bin/env bash
set -e
SRC=$PWD/src
HTML=$SRC/html
TEMPLATES=$(find "$SRC/templates" -iname '*.html')
web-build $HTML/begin.html \
$HTML/${1:-development}.html \
$HTML/head.html \
$HTML/begin-body.html \
$HTML/body.html \
$TEMPLATES \
$HTML/end.html \
serve -m -v --static $SRC --port ${2:-8080}
"start": ".\scripts\serve" change it to
"start": "node ./scripts/serve"
As Jonathan Jonathan mentioned in the comment you need to try this
"start": "node ./scripts/server,js"
or try something like this
"start": "cd scripts && node server.js"

Node/React app won't deploy to Heroku

My app has a React frontend and a Node backend; the BE serves the FE data through an API. It won't deploy to Heroku—stack trace is below.
Things I've tried:
This question. I've tried modelling my package.json files after a model repo mentioned in the answer, but no luck.
Deploying the model repo mentioned above—it worked fine.
Deploying the model repo to my own failing heroku app—it worked fine, so Heroku isn't the issue.
This question (I've checked react-scripts is listed as a dependency and not a dev-dependency).
I will probably end up taking the model repo as a starting point and gradually copying my project over, but would appreciate any info on what might be going wrong.
Stack Trace:
> fsevents#1.0.17 install /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents
> node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v48-linux-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for fsevents#1.0.17 and node#6.10.3 (node-v48 ABI) (falling back to source compile with node-gyp)
make: Entering directory '/tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents/build'
SOLINK_MODULE(target) Release/obj.target/.node
COPY Release/.node
make: Leaving directory '/tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents/build'
> fibers#1.0.15 install /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fibers
> node build.js || nodejs build.js
`linux-x64-48` exists; testing
Binary is fine; exiting
added 1242 packages in 52.433s
removed 1242 packages in 25.561s
> react-ui#0.1.0 build /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client
> react-scripts build
sh: 1: react-scripts: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! react-ui#0.1.0 build: `react-scripts build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-ui#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
My server package.json:
{
"name": "in-search-of-happiness",
"engines": {
"node": "6.10.x"
},
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"heroku-postbuild": "cd client/ && npm install --only=dev && npm install && npm run build"
},
"cacheDirectories": [
"node_modules",
"client/node_modules"
],
"dependencies": {
"body-parser": "^1.17.2",
"cookie-parser": "^1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jade": "^1.11.0",
"mongoose": "^4.10.8",
"morgan": "^1.8.2",
"serve-favicon": "^2.4.3",
"zombie": "^5.0.5"
}
}
My React package.json:
{
"name": "react-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^3.3.7",
"fetch": "^1.1.0",
"node-fetch": "^1.7.1",
"process-nextick-args": "^1.0.7",
"react": "^15.6.1",
"react-bootstrap": "^0.31.0",
"react-dom": "^15.6.1",
"react-scripts": "1.0.7",
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"chai": "^4.0.2",
"eslint": "^4.0.0",
"sinon": "^2.3.5",
"wdio-mocha-framework": "^0.5.10",
"webdriverio": "^4.8.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001"
}
Hello your post build script needs some modification, kindly follow this convention
Replace reactFolderName to your folder name that contains the react frontend
Add This below snippet to your package.json under the scripts
scripts{
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix reactFolderName && npm run build --prefix reactFolderName"
}
And add this snippet to your index.js file
app = express()
app.use(express.static('reactFolderName/build'));
app.get('*', (req, res) => res.sendFile(path.resolve(__dirname, 'reactFolderName', 'build', 'index.html')));

Resources