Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Snackpack's avatar

Error when running npm install && npm run dev

have a fresh installation of laravel and I've installed npm. but when I run npm install && npm run dev I get this error

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ] 2 info using [email protected] 3 info using [email protected] 4 verbose run-script [ 'predev', 'dev', 'postdev' ] 5 info lifecycle @~predev: @ 6 info lifecycle @~dev: @ 7 verbose lifecycle @~dev: unsafe-perm in lifecycle true 8 verbose lifecycle @~dev: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/xxx/laravel/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin 9 verbose lifecycle @~dev: CWD: /var/www/xxx/laravel 10 silly lifecycle @~dev: Args: [ '-c', 'npm run development' ] 11 silly lifecycle @~dev: Returned: code: 2 signal: null 12 info lifecycle @~dev: Failed to exec dev script 13 verbose stack Error: @ dev: npm run development 13 verbose stack Exit status 2 13 verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:198:13) 13 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:198:13) 13 verbose stack at maybeClose (internal/child_process.js:982:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) 14 verbose pkgid @ 15 verbose cwd /var/www/xxx/laravel 16 verbose Linux 4.19.0-13-amd64 17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev" 18 verbose node v10.23.1 19 verbose npm v6.14.11 20 error code ELIFECYCLE 21 error errno 2 22 error @ dev: npm run development 22 error Exit status 2 23 error Failed at the @ dev script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 2, true ]

please help me!

0 likes
1 reply
bobbybouwmann's avatar

Normally it helps just deleting the node_modules directory and running it again. If that doesn't work try deleting the package-lock.json and run the command again.

Your final option is to clear the cache from npm

rm -rf node_modules
rm -rf package-lock.json
npm cache clean --force
npm install && npm run dev

Please or to participate in this conversation.