NativeScript 'Create' new project failed - EACCES: permission denied on macOS


#1

I’m new to Mac, to macOS development and to NativeScript.

I’m trying to start a new tns project using:

sudo tns create rsrpt --ng

and I get this error all the time:

Error: EACCES: permission denied, mkdir '/Users/myUser/code/rsrpt/hooks'

Out of frustration, after 10 hours, I ran the following commands:

sudo chown -R $(whoami) ~/.local

and even this: (I hope I didn’t ruin permissions on this mac)

sudo chown -R $(whoami) ~/

But nothing helped. I still get the attached detailed error. Any help on how to overcome this permission problem would be appreciated! Thanks!

> nativescript-angular@6.1.0 postinstall /Users/myUser/code/rsrpt/node_modules/nativescript-angular
> node postinstall.js

fs.js:885
  return binding.mkdir(pathModule._makeLong(path),
                 ^

Error: EACCES: permission denied, mkdir '/Users/myUser/code/rsrpt/hooks'
    at Object.fs.mkdirSync (fs.js:885:18)
    at Object.<anonymous> (/Users/myUser/code/rsrpt/node_modules/nativescript-angular/postinstall.js:11:12)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nativescript-angular@6.1.0 postinstall: `node postinstall.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nativescript-angular@6.1.0 postinstall 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!     /Users/myUser/.npm/_logs/2018-08-14T00_22_47_432Z-debug.log
Command npm install failed with exit code 1
# tns create

┌───────────────┬────────────────────────────────────────────────────────────┐
│ Usage         │ Synopsis                                                   │
│ Create from   │ $ tns create <App Name> [--path <Directory>] [--appid <App │
│ default       │ ID>]                                                       │
│ JavaScript    │                                                            │
│ template      │                                                            │
│ Create from   │ $ tns create <App Name> --template typescript [--path      │
│ default       │ <Directory>] [--appid <App ID>] OR $ tns create <App Name> │
│ TypeScript    │ --tsc [--path <Directory>] [--appid <App ID>] OR $         │
│ template      │ tns create <App Name> --template tsc [--path <Directory>]  │
│               │ [--appid <App ID>]                                         │
│ Create from   │ $ tns create <App Name> --template angular [--path         │
│ default       │ <Directory>] [--appid <App ID>] OR $ tns create <App Name> │
│ Angular       │ --template ng [--path <Directory>] [--appid <App ID>]      │
│ template      │ OR $ tns create <App Name> --ng [--path <Directory>] [-    │
│               │ -appid <App ID>]                                           │
│ Copy from     │ $ tns create <App Name> [--path <Directory>] [--appid <App │
│ existing      │ ID>]                                                       │
│ project       │                                                            │
│ Create from   │ $ tns create <App Name> [--path <Directory>] [--appid <App │
│ custom        │ ID>] --template <Template>                                 │
│ template      │                                                            │
└───────────────┴────────────────────────────────────────────────────────────┘

Creates a new project for native development with NativeScript.

### Options

    * --path - Specifies the directory where you want to create the project, if different from the current directory. The directory must be empty.
    * --appid - Sets the application identifier for your project.
    * --template - Specifies a valid npm package which you want to use to create your project. If --template is not set, the NativeScript CLI creates the project from the default JavaScript hello-world template.
    * --ng - Sets the template for your project to the Angular template.
    * --tsc - Sets the template for your project to the TypeScript template.

### Attributes

    * <App Name> is the name of project. The specified name must meet the requirements of all platforms that you want to target. For more information about the <App Name> requirements, run $ tns help create
    * <App ID> is the application identifier for your project. It must be a domain name in reverse and must meet the requirements of all platforms that you want to target. If not specified, the application identifier is set to org.nativescript.<App name> For more information about the <App ID> requirements, run $ tns help create

#2

Hi Mick,

I ran into same issue, this is purely due to ownership permissions to your npm, .config directories inside your home.

Change your npm permission by issuing the following command.
Preformatted textsudo chown -R myUser /usr/local/lib/node_modules
Preformatted textsudo chown -R myUser /usr/local/bin
Preformatted textsudo chown -R myUser /usr/local/share

After this, inside your home folder “/Users/myUser/”, there is a .config file that needs to be changed as well.

Preformatted textsudo chown -R myUser /Users/myUser/.config

Now create a new tns angular project, It should create one.

Cheers!


#3

Amazing. Thanks for this. It seems like a restart was needed after running:

sudo chown -R $(whoami) ~/

Again, I hope I didn’t ruin all permissions for this mac, but that solved the problem.
Thanks!