npm errors while trying to run json scripts on new laptop - node.js

I did an online course about coding, which included a couple of small scripts to compile my sass and concat my css files. Recently I got a new laptop and I did install node, installed my dependencies but for some reason I can't get any of them to work.
Here is what I did:
Installed node (current version: v10.15.2)
Did npm install and:
* sudo npm install live-server -g
* npm install autoprefixer --save-dev
* npm install postcss-cli --save-dev
Here are my json scripts:
"scripts": {
"watch:sass": "node-sass sass/main.scss css/style.css -w",
"devserver": "live-server",
"start": "npm-run-all --parallel devserver watch:sass",
"compile:sass": "node-sass sass/main.scss css/style.comp.css",
"concat:css": "concat -o css/style.concat.css css/icon-font.css css/style.comp.css",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/style.concat.css -o css/style.prefix.css",
"compress:css": "node-sass css/style.prefix.css css/style.css --output-style compressed",
"build:css": "npm-run-all compile:sass concat:css prefix:css compress:css"
},
Here I my errors:
` npm start
> talentsfestivals#1.0.0 start /Users/vasil.krumov/Documents/Projects/TalentsFestivals
> npm-run-all --parallel devserver watch:sass
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '../common/bootstrap'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/vasil.krumov/Documents/Projects/TalentsFestivals/node_modules/.bin/npm-run-all:13:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! talentsfestivals#1.0.0 start: `npm-run-all --parallel devserver watch:sass`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the talentsfestivals#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! /Users/vasil.krumov/.npm/_logs/2019-03-03T15_29_19_750Z-debug.log `
Can anyone please help me?
Thanks so much in advance!

For the sake of others searching for the solution to your problem, i will write it here to make it easier to locate.
The first problem seemed to be some old modules, to clean it up remove you modules folder and npm install again.
The next problem seemed to be EACCES permissions errors. Usually you don't want to sudo install npm packages. If you have EACCES permissions errors look at this documentation

Related

Next.js tutorial, error running Next.js dev server (npm run dev)

I'm doing the starter Next.js tutorial and encountering an error when I try to run the Next dev server and run my app.
Here is what my package.json file contains:
{
"scripts": {
"dev": "next dev"
},
"dependencies": {
"next": "^12.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
When running npm run dev, I get the following error:
> # dev /Users/renaudj/Documents/Projects/next-app
> next dev
/Users/renaudj/Documents/Projects/next-app/node_modules/next/dist/trace/report/index.js:14
reporters = [];
^
SyntaxError: Unexpected token =
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # 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! /Users/renaudj/.npm/_logs/2022-07-04T05_09_15_196Z-debug.log
Anyone know what I'm missing here? Thank you!
I update my node version V11.15.1 to V12.22.1 then it's solved
I update my node version V10->V16. it' work
Yes, updating your version of node will solve this issue.
Before doing this, delete the node_modules folder in your project.
Then to update node to the latest stable version, run the following command on your terminal:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
You may need to restart your terminal to see the version update which you check using:
node -v
Then reinstall your project using
npm install
Basically I have multiple versins of node.
It is possible through nvm
I switched to node 14 using the command :
node use 14.15.0

Endless Loop: Cannot find 'cross-spawn'

Problem
I am stuck in a loop where running npm run watch says it cannot find cross-spawn.
> # watch /Users/donnie/Github/laravel_project
> npm run development -- --watch
> # development /Users/donnie/Github/laravel_project
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch"
module.js:549
throw err;
^
Error: Cannot find module 'cross-spawn'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/donnie/.yarn-cache/npm-cross-env-5.2.0/dist/index.js:5:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # development 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/donnie/.npm/_logs/2019-01-22T21_57_39_199Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # watch: `npm run development -- --watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # watch 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/donnie/.npm/_logs/2019-01-22T21_57_39_227Z-debug.log
I run npm i --D cross-spawn which is successful, then npm run watch again. It says there are a few more dependencies that must be installed (which is strange because the first thing I did was npm install.) Anyway, it finally provides this feedback:
Okay, done. The following packages have been installed and saved to your package.json dependencies list:
- vue-template-compiler
- sass-loader#7.*
- sass
- resolve-url-loader#2.3.1
Finished. Please run Mix again.
Cool. So I run npm run watch again and we're right back to the cross-spawn problem.
I've tried deleting /node_modules and starting fresh. No luck.
🤔
package.json
{
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"cross-spawn": "^6.0.5"
"false": "^0.0.4",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"resolve-url-loader": "2.3.1",
"sass": "^1.16.1",
"sass-loader": "7.*",
"vue": "^2.5.17",
"vue-template-compiler": "^2.5.22"
},
"dependencies": {}
}
Environment
npm: 6.3.0
laravel: 5.7
Running npm rebuild then npm install should fix the problem. Now, running npm run dev should build fine.
I believe this issue has something to do with bad file permissions and npm rebuild seems to sort things out.
Ran into a similar issue with craco.
The following fixed it for me:
rm -rf node_modules
rm package-lock.json
npm install
Edit: I should mention that this is less than optimal. Removing your lock file is generally a bad idea and can result in dependency conflicts. In my specific case, it didn't matter, but it may matter in yours. Take precautions if you plan on applying this "fix" (create a backup if you don't use git).

any solution for the following error that appeared after installing onchange and parallelshell node_modules?

after installing the onchange and parallelshell packages for node.js by typing the following command in the node terminal
npm install --save-dev onchange#3.3.0 parallelshell#3.0.2
and configure the package.json file as follow to be able to use the two scripts
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" --npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
}
and when typing 'npm start' to run, i face the following error and cannot solve it. so help me if u can please!
The Error :
confusion#1.0.0 start D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion
npm run watch:all
confusion#1.0.0 watch:all D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion
parallelshell "npm run watch:scss" "npm run lite"
child_process.js:420
throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
at normalizeSpawnArguments (child_process.js:420:11)
at spawn (child_process.js:522:38)
at D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion\node_modules\parallelshell\index.js:104:17
at Array.forEach ()
at Object. (D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion\node_modules\parallelshell\index.js:100:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 watch:all: parallelshell "npm run watch:scss" "npm run lite"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 watch:all 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\MISR COMP\AppData\Roaming\npm-cache_logs\2018-07-30T15_48_55_679Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 start: npm run watch:all
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#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\MISR COMP\AppData\Roaming\npm-cache_logs\2018-07-30T15_48_55_778Z-debug.log
I have had the same problem as you. We are probably doing the same course. Apparently, is a problem with version 3.0.2 of parallelshell. You just have to downgrade to version 3.0.1 and you will not have any more problems:
npm install --save-dev parallelshell#3.0.1
Downgrade the version of parallelshell to 3.0.1 by typing
npm install --save-dev parallelshell#3.0.1
Then type
npm start
And it works!!
Apparently we are doing the same course. So follow the below-mentioned way--
To install two NPM packages onchange and parallelshell use the downgraded version of parallel shell instead of 3.0.2 us 3.0.1:
npm install --save-dev onchange#3.3.0 parallelshell#3.0.1
give space between -- and npm
"watch:scss":"onchange \"css/*.scss\" -- npm run scss"
this will end first error
for parallelshell problem
do this copy content of index.js file from given link
https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
and paste it in your index.file at /project/node_modules/parallelshell/index.js
this will work.
First Un-Install all versions of parallelshell.
npm uninstall --save-dev parallelshell
Second Install parallelshell#3.0.1:
npm install --save-dev parallelshell#3.0.1
Third run start:
npm run start

Error: Cannot find module './util/resolveCommand'

I'm not able to npm start anymore due to a problem with the util npm I think.
I tried to update all the packages and to remove util and re-install it. How could I solve this?
Error: Cannot find module './util/resolveCommand'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/cyruslognonne/Dropbox/C-T-L-K_Master/A_Mandats/A_En cours/LEV/B_Jam/lev_dev/node_modules/cross-spawn/lib/parse.js:3:22)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lev_dev#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lev_dev#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/cyruslognonne/.npm/_logs/2017-12-03T19_21_25_874Z-debug.log
Here's my package.json.
{
"name": "lev_dev",
"version": "0.1.0",
"private": true,
"dependencies": {
"package.json": "^2.0.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-marquee": "^0.1.1",
"react-scripts": "1.0.17",
"react-slick": "^0.15.4",
"slick-carousel": "^1.8.1",
"util": "^0.10.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Thanks, Cyrus
As the error states, the problem is with the cross-spawn module, which is used by react-scripts. The issue is not because of util module.
Try the following to update the dependencies properly and see if it works.
npm install -g npm#latest # to update npm.
rm -rf node_modules # to remove the existing modules.
npm install # to re-install the project dependencies.
You firstly need to
npm clean cache force
and then go to your git bash if you are using windows and run
rm -rf node_modules
and after removing the node_modules then run
npm install

SyntaxError: missing ) after argument list | nodejs | `npm start`

Running npm start is giving me a syntax error, shown in the output below.
I know how to fix a simple syntax error but I doubt that's the issue here. Looking through various forums didn't result in an answer for me.
[nodemon] starting `npm run lint && node src/app.js`
> server#1.0.0 lint C:\Users\brend\project\server
> node ./node_modules/.bin/eslint **/*.js
C:\Users\brend\project\server\node_modules\.bin\eslint:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramFiles\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "lint"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! server#1.0.0 lint: `node ./node_modules/.bin/eslint **/*.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 lint script 'node ./node_modules/.bin/eslint **/*.js'.
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 server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./node_modules/.bin/eslint **/*.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs server
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls server
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\brend\project\server\npm-debug.log
[nodemon] app crashed - waiting for file changes before starting...
Below is the package.json.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node ./node_modules/nodemon/bin/nodemon.js src/app.js --exec \"npm run lint && node\" ",
"lint": "node ./node_modules/.bin/eslint **/*.js"
},
Ugh.. Okay first thing I ran into was an error saying that '.' is not recognized as an internal or external command. I googled and came to the conclusion that I needed to put node before the script. This resulted in progress; namely that it actually ran the script. Turns out it was needed at the "start" script but not the "lint" script.
My package.json scripts now look like this:
"scripts": {
"start": "node ./node_modules/nodemon/bin/nodemon.js src/app.js --exec \"npm run lint && node\" ",
"lint": "./node_modules/.bin/eslint **/*.js"
},
Which results in:
[nodemon] starting `npm run lint && node src/app.js`
> server#1.0.0 lint C:\Users\brend\project\server
> eslint **/*.js
hello
[nodemon] clean exit - waiting for changes before restart
ps: Thank you for your help kind strangers!

Resources