Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sh: 1: cross-env: Permission denied on laravel mix

I'm trying to run npm run dev but the following error occur:

sh: 1: cross-env: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
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.
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!     /home/shanmaseen/.npm/_logs/2019-02-22T16_32_08_191Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 126
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!     /home/shanmaseen/.npm/_logs/2019-02-22T16_32_08_241Z-debug.log

I've been searching the internet for a week, nothing helped at all !

I even tried to remove 'cross-env' from package.json scripts, but then webpack: permission denied happened, indicating that the permission error is not by cross-env it self.

this is the error log:

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:/media/e/www/mwar/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle @~dev: CWD: /media/e/www/mwar
10 silly lifecycle @~dev: Args: [ '-c', 'npm run development' ]
11 silly lifecycle @~dev: Returned: code: 126  signal: null
12 info lifecycle @~dev: Failed to exec dev script
13 verbose stack Error: @ dev: `npm run development`
13 verbose stack Exit status 126
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:197:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:197:13)
13 verbose stack     at maybeClose (internal/child_process.js:984:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid @
15 verbose cwd /media/e/www/mwar
16 verbose Linux 4.18.0-15-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v11.10.0
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 126
22 error @ dev: `npm run development`
22 error Exit status 126
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 [ 126, true ]

I'm using laravel 5.7mix.

node version: v11.10.0 npm version: 6.7.0

any help please?

like image 873
shamaseen Avatar asked Feb 22 '19 16:02

shamaseen


5 Answers

I was on ubuntu 18.

Following command helped me :-)

npm rebuild

Documented as follows, on the official website.

This command runs the npm build command on the matched folders. This is useful when you install a new version of node, and must recompile all your C++ addons with the new binary. It is also useful when installing with --ignore-scripts and --no-bin-links, to explicitly choose which packages to build and/or link bins.

If one or more package names (and optionally version ranges) are provided, then only packages with a name and version matching one of the specifiers will be rebuilt.

like image 191
zarpio Avatar answered Oct 24 '22 00:10

zarpio


This is because of permission issues with global installation of packages, which npm is being denied access.

To solve this try

1.

npm rebuild

npm run watch

Or 2

rm -Rf node_modules

npm install

npm run watch

Hope it works.

like image 39
Tinashe Avatar answered Oct 23 '22 23:10

Tinashe


The following thing worked for me

chmod -R a+x node_modules

source

like image 34
habib Avatar answered Oct 23 '22 23:10

habib


As @savedbeau suggests, running the following fixes this problem:


npm rebuild

followed by

npm run watch
like image 11
hackernewbie Avatar answered Oct 23 '22 23:10

hackernewbie


If file (and folder) permissions were changed to more restrictive ones, a permission error like the following can happen on Ubuntu:

$ npm run watch

> watch
> mix watch

sh: 1: mix: Permission denied

to resolve that on Ubuntu, this might work - it worked for me:

chmod -R u+x node_modules

It gives(+) the user(u) execution(x) permission recursively(-R) to everything inside the node_modules folder.

Be careful, think about security and do not use the a flag (instead of the u flag) to give everybody execution rights.

like image 9
Emil Carpenter Avatar answered Oct 23 '22 23:10

Emil Carpenter