Laravel: npm run watch Error - node.js

I was working on a project and I run 'npm run watch'
and I got this error. I was working normally but all of sudden I got this error!
> # watch C:\projects\tests\blog
> node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development
node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --
config=node_modules/laravel-mix/setup/webpack.config.js
undefined:1
SyntaxError: Unexpected token
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe"
"C:\\Users\\Bruno\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch"
npm ERR! node v6.10.0
npm ERR! npm v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # watch: `node node_modules/cross-env/dist/bin/cross-env.js
NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # watch script 'node node_modules/cross- env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.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 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node node_modules/cross-env/dist/bin/cross-env.js
NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Bruno\AppData\Roaming\npm-cache\_logs\2017-03-20T13_06_27_111Z-debug.log
What should I do?

If you are developing on a Windows system or you are running your VM on a Windows host system, you may need to run the npm install command with the --no-bin-links switch enabled:
Install using this command:
npm install --no-bin-links
And run this after:
npm run watch-poll
Source for 5.4
Source for <= 5.3

I just simply deleted built CSS and JS files as well as the mix-manifest.json file. Things worked afterwards

For me just deleted the mix-manifest.json file. Then did npm run watch-poll
My package.json script.
"scripts": {
"dev": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
Running laravel from xampp shell (windows 7)

Note: Make sure you have the latest version of node.js and npm installed.
Clear NPM's cache:
sudo npm cache clean -f
Install called 'n':
sudo npm install -g n
Install latest stable Node.js version: sudo n stable
Alternatively pick a specific version and install like this:
sudo n (wanted node version)
You can get information on how to open an issue for this project with: npm bugs
It's literally described in the log output what to do...

try this also:
npm uninstall --save-dev sass-loader
It just ran perfectly when i tried to run the command npm run dev / npm run watch

Related

npm: start script fails

I'm developing a simple backend project with Node.js (v12.16.1) on Windows 10.
My package.json file contains the following command:
"scripts": {
"start": "NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env",
...
}
And when I type npm run start, I get
> NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env
'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! devcamper-api#1.0.0 start: `NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the devcamper-api#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Why does this failure occure?
Windows doesn't understand this way of setting environment variables.
Use cross-env package instead: https://www.npmjs.com/package/cross-env
npm install --save-dev cross-env
and then in your script:
"cross-env NODE_ENV=production ... "

Trying to run "npm run dev" but it doesn't work

I'm on windows working on a new laravel project everything worked good so far but when i tried to run this command i had those errors :
C:\Users***\Documents\files\Laravel\RSWebSite > npm run dev
'CALL "C:\Program Files\nodejs\node.exe" "C:\Program
Files\nodejs\node_modules\npm\bin\npm-cli.js" prefix -g' n'est pas
reconnu en tant que commande interne ou externe, un programme
exécutable ou un fichier de commandes.
> # dev C:\Users\***\Documents\files\Laravel\RSWebSite
> npm run development
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn C:\windows\system32\cmd.exe;
npm ERR! file C:\windows\system32\cmd.exe;
npm ERR! path C:\windows\system32\cmd.exe;
npm ERR! errno ENOENT
npm ERR! # dev: `npm run development`
npm ERR! spawn C:\windows\system32\cmd.exe; ENOENT
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! C:\Users\***\AppData\Roaming\npm-cache\_logs\2019-10-22T14_06_36_677Z-debug.log
This is my package.json file:
{
"private": true,
"scripts": {
"dev": "npm run development",
"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 run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "7.*",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
}
}
you need to delete package-lock.json or yarn.lock then clear npm caches, you can do this by implementing those commands
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
I encountered this most of the time when I pull a new project.
try doing this.
npm install
npm audit fix
then run it again sometimes the cause of this is missing packages .

npm install error in laravel 5.6 with fresh installation

I get the following error while running npm install on a fresh laravel 5.6 installation on windows 7 32 bit, npm version 5.7.1, node v9.5.0
npm ERR! path
D:\xampp\htdocs\2018\thehealthsearch\node_modules\node-sass\node_modules\har-validator\bin\har-validator
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod 'D:\xampp\htdocs\2018\thehealthsearch\node_modules\node-sass\no
de_modules\har-validator\bin\har-validator'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-14T05_58_42_171Z-debug.log
How to resolve this?
EDIT :
My Package.json file
{
"private": true,
"scripts": {
"dev": "npm run development",
"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": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"popper.js": "^1.12",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"vue": "^2.5.16"
},
"dependencies": {
"har-validator": "^5.1.0",
"yarn": "^0.16.1"
}
}
You need to try this commands line by line:
npm cache clean
npm install -g gulp bower
npm install
bower install
gulp & gulp watch
This commands do:
for cleaning a cache of npm
installs gulp bower globally
installs npm
installs bower
for mixing all js and css and watch on all changes of css & js
Hope this will helps you and fixed your issue!

yarn run dev - cross-env: Permission denied

My dev environment is Vagrant ScotchBox, Node 6.6.2, Npm 3.9.5.
I'm trying to compile the assets of my Laravel project using Mix.
yarn install
yarn run dev
With yarn run dev i get sh: 1: cross-env: Permission denied
sh: 1: cross-env: Permission denied
npm ERR! Linux 3.13.0-55-generic
npm ERR! argv "/home/vagrant/.nvm/versions/node/v6.2.2/bin/node" "/home/vagrant/.nvm/versions/node/v6.2.2/bin/npm" "run" "development"
npm ERR! node v6.2.2
npm ERR! npm v3.9.5
npm ERR! code ELIFECYCLE
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`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the # development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.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 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/public/your-weedelivero/npm-debug.log
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c npm run development
Directory: /var/www/public/your-weedelivero
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/var/www/public/your-weedelivero/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Please, someone can help me?
Regards
/////////////////
maybe my package.json is wrong
{
"private": true,
"scripts": {
"dev": "npm run development",
"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": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.17",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.1.3",
"jquery": "^3.2",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.5.7"
}
}
I Had this problem in my ubuntu 16.04.
for me, it fixes the problem
first, get into your directory in terminal and enter below command.
npm rebuild
I just remove the Nodejs and install the latest version of Nodejs and now I don't have this problem anymore
Laravel Mix "sh: 1: cross-env: not found error"

working node.js projects on windows 10 now no longer working

Node.js projects are no longer working. Have node.js 7.10.x npm 4.2.1
Projects that were working are no longer working. I uninstalled node.js, removed npm-cache, reinstalled fresh. Deleted node_modules directory, ran npm install on project's package.json and npm start xxxx etc. No matter what project I run, the error remains the same as shown below. The same projects installed on Linux Ubuntu work just fine.
No clue as to why these projects are no longer working. The following error is consistent with each node project I've tested.
Any help would be appreciated. Thanks in advance.
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! muber#1.0.0 test: `NODE_ENV=test nodemon --exec 'mocha --recursive -R min'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the muber#1.0.0 test script 'NODE_ENV=test nodemon --exec 'mocha --recursive -R min''.
npm ERR! Make sure you have the latest version of node.js and npm installed.
I think I know what the problem is if it works on Linux but not the Windows machine. Windows cannot run CLI scripts the same; it requires a different syntax.
To fix it, you simply have to do npm install --save cross-env and then in your package.json file, add cross-env to the beginning of the script declaration:
ie:
"scripts": {
"start": "NODE_ENV=test nodemon --exec 'mocha --recursive -R min'"
},
will become:
"scripts": {
"start": "cross-env NODE_ENV=test nodemon --exec 'mocha --recursive -R min'"
},
That should fix it.
To fix it on Windows, you'd have to change it to (I think):
"scripts": {
"start": "NODE_ENV=test&&nodemon --exec 'mocha --recursive -R min'"
},
You can do a quick test and change it to that and run it. If that fixes it, this is exactly your problem. But, that will break it on Linux, so generally, cross-env is recommended. Make sure you dont have spaces also at &&.

Resources