apache / cordova

Apache Cordova
https://cordova.apache.org/
583 stars 61 forks source link

Cordova create testProject on smb volume #384

Closed damienf55 closed 1 year ago

damienf55 commented 1 year ago

Hi Cordova team

When I create a new project on my Macintosh (OS Monterey) on smb volume with full rights for me, there are an error :

cordova create MyProject :

Creating a new cordova project. EACCES: permission denied, copyfile '/usr/local/lib/node_modules/cordova/node_modules/cordova-app-hello-world/template_src/config.xml' -> '/Volumes/furiet5/cordovaTest/config.xml'

I'have no error with in a foder localy on my Macintosh

Thank you for help me

damienf55 commented 1 year ago

with verbose mode :

Using detached cordova-create Creating a new cordova project. Copying assets. EACCES: permission denied, copyfile '/usr/local/lib/node_modules/cordova/node_modules/cordova-app-hello-world/template_src/config.xml' -> '/Volumes/furiet5/cordovaTest/config.xml' Error: EACCES: permission denied, copyfile '/usr/local/lib/node_modules/cordova/node_modules/cordova-app-hello-world/template_src/config.xml' -> '/Volumes/furiet5/cordovaTest/config.xml' at Object.copyFileSync (node:fs:2817:3) at copyFile (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:73:6) at onFile (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:59:25) at getStats (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:51:44) at startCopy (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:41:10) at copyDirItem (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:125:10) at /usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:118:39 at Array.forEach () at copyDir (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:118:23) at onDir (/usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/copy/copy-sync.js:108:10)

breautek commented 1 year ago

'/usr/local/lib/`

is generally a path reserved for root, and is what I think is likely the source of the permission issue. Cordova is likely have been installed root (e.g. sudo npm install -g cordova) which isn't recommended, as it means cordova will need to be root in order to copy files from node_modules and do most of it's operations.

Instead, NPM should be configured to use a global directory owned by your own user account, so you can use NPM to install packages globally without using sudo.

Personally, I'd recommend using nvm (Node Version Manager) which installs local versions of a node at a version your choice. You could have multiple versions installed and easily switch between them, and it configures things in a way by default where you don't need sudo.

let me know if this helps.

damienf55 commented 1 year ago

Hi, cordova is installed for all users, so I use sudo npm install -g cordova. My computers are multi-users for courses of our University ... I cant install cordova for all students... Do you have a doc to install cordova with `nvm' ?

Thanks

breautek commented 1 year ago

Do you have a doc to install cordova with `nvm' ?

No, the cordova docs just has a brief mention regarding nvm. This should still work on a multi-user machine, but NVM will only be installed for your user. If this is a multi-user university machine however, and all users should have access to Node, then NVM might not be the best option.

NVM is just a node manager so you can then install different versions of node at the user-level. For example, if you want to use Node 16 by default, then you would do:

nvm install 16
nvm alias default 16

You can have multiple versions installed at the same time and switch between them (every Node install have their own global packages folder)

nvm install 18
nvm use 18
# now node/npm references are using Node 18 for the active session, but a new terminal will still 16 as the default as configured above

Because Node is user level, you don't need root or sudo to install global packages because they get installed at a user-level directory (inside ~/.nvm). e.g. you can run npm install -g cordova

I cant install cordova for all students

NVM is a user-level (shell) program, it won't be installed for all students. Any node versions installed through NVM is also user-level install, only your user has access to it.

Additionally because of this, you can now use npm install -g <package> without using root or sudo because these packages are installed under a nvm user-level directory. For example:

$ which node
/home/norman/.nvm/versions/node/v18.15.0/bin/node
$ which cordova
/home/norman/.nvm/versions/node/v18.15.0/bin/cordova

To install NVM, see their installation

If you don't want to use NVM, it is also possible to configure NPM to not use a system directory which requires root by setting the prefix option. This config can be set to a user directory such as ~/.npm-globals so that when you install global packages, it won't require sudo. But it sounds like you want a local user node install, not a system wide node install, so using NVM would be a way to achieve that.

From a security standpoint, using NVM or at least configuring NPM to not use root owned directories is beneficial because it means you don't need to use sudo when installing. The drawback of requiring sudo is that you're giving many packages root level privileges during the installation, so you're making your self vulnerable to malicious packages that could do wide harm to the machine in general while running under root.

damienf55 commented 1 year ago

Ok, thank-you for helping. I will check that later Bye