2
votes

I want to execute "npm run watch" in my laravel project but it doesn't work. There is the error message

@ watch /Applications/MAMP/htdocs/test-tech/laravel5 npm run development -- --watch

@ development /Applications/MAMP/htdocs/test-tech/laravel5 cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch"

sh: cross-env: command not found npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn 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! spawn ENOENT 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 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! /Users/xxx/.npm/_logs/2019-03-29T11_19_55_390Z-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 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! /Users/xxx/.npm/_logs/2019-03-29T11_19_55_422Z-debug.log

And the debug file

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'watch' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle @~prewatch: @
6 info lifecycle @~watch: @
7 verbose lifecycle @~watch: unsafe-perm in lifecycle true
8 verbose lifecycle @~watch: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Applications/MAMP/htdocs/test-tech/laravel5/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle @~watch: CWD: /Applications/MAMP/htdocs/test-tech/laravel5
10 silly lifecycle @~watch: Args: [ '-c', 'npm run development -- --watch' ]
11 silly lifecycle @~watch: Returned: code: 1  signal: null
12 info lifecycle @~watch: Failed to exec watch script
13 verbose stack Error: @ watch: `npm run development -- --watch`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid @
15 verbose cwd /Applications/MAMP/htdocs/test-tech/laravel5
16 verbose Darwin 18.2.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "watch"
18 verbose node v8.11.3
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error @ watch: `npm run development -- --watch`
22 error Exit status 1
23 error Failed at the @ watch script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I googled it and tried some solutions but it still doesn't work. How to resolve it ?

Thanks

1
npm run dev includes watch. Unless you have npm-watch package that's not a valid command. I only saw the watch flag explicit with yarn. Do npm --help to see available commandsIndra
something more to add: you can do npm run <script> if you have that script in your project. So npm run watch needs a watch script in order to run. You can add that in package.json under the scripts objectIndra
I have this in my package.json scripts for watch : "watch": "npm run development -- --watch", "watch-poll": "npm run watch -- --watch-poll",Cohchi
is the env set globaly? try: npm install --global cross-env edit: check this out: stackoverflow.com/questions/43685777/…Indra

1 Answers

6
votes

The problem is that you are missing cross-env, you can run npm install -g cross-env to install it globally, or npm install cross-env to install it locally in the current project.