Nativescript-cli: Permissions denied when crating app `tns create MyApp`

Created on 7 Nov 2018  路  2Comments  路  Source: NativeScript/nativescript-cli

I am running the latest LTS Node (10.13.10 LTS) on Ubuntu 18.04.1 LTS.

I installed NativeScript using sudo npm install nativescript -g --unsafe-perm

I am now trying to create an app using tns create MyApp but I got the error

Error: EACCES: permission denied, open '/home/matt/.npm/_cacache/index-v5/f7/86/8fb370ae1f6975b75ea9124c8167ff79c3d10c69413aff4a265084641be9'

So I tried again using sudo tns create MyApp but instead got a different permissions error.

> [email protected] postinstall /home/matt/Documents/programming/node/nativescript/MyApp/node_modules/nativescript-dev-webpack
> node postinstall.js

/home/matt/Documents/programming/node/nativescript/MyApp/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/home/matt/Documents/programming/node/nativescript/MyApp/hooks'
    at Object.mkdirSync (fs.js:750:3)

etc

So far I have tried commands for chown as I have been looking online:

sudo chown -R matt /usr/local/lib/node_modules
sudo chown -R matt /usr/local/bin
sudo chown -R matt /usr/local/share

but still doesn't work

Any help is appreciated, thank you!

question

Most helpful comment

Hi @Hopson97 ,
The sudo tns create MyApp fails because it eventually executes a npm install over the new application, which is OK as it inherits the sudo from the create command, but the postinstall scripts fail to execute with root privileges as the CLI does't use --unsafe-perm for the npm install.

To fix the already created application you can run sudo npm install --unsafe-perm in the root of the project. This will execute the postinstall scripts with the right permissions.

To fix project creation in general you can try sudo chown -R matt /home/matt/.npm. This should allow you to run tns create MyApp without adding sudo.

All 2 comments

Hi @Hopson97 ,
The sudo tns create MyApp fails because it eventually executes a npm install over the new application, which is OK as it inherits the sudo from the create command, but the postinstall scripts fail to execute with root privileges as the CLI does't use --unsafe-perm for the npm install.

To fix the already created application you can run sudo npm install --unsafe-perm in the root of the project. This will execute the postinstall scripts with the right permissions.

To fix project creation in general you can try sudo chown -R matt /home/matt/.npm. This should allow you to run tns create MyApp without adding sudo.

Fantastic, this worked perfectly.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings