-
Notifications
You must be signed in to change notification settings - Fork 334
document using npm with a version manager to avoid permissions errors #240
Comments
how do you have node installed? |
I have
|
We should stop trying to install Wrangler into the user's $HOME, or locally to the project, and require sudo. In the case that the Nodejs installation allow global write access by the user, they will get a permission error (because we will try to install in |
FWIW I personally very much prefer to install tools locally to a project even when the tool authors think I should install it globally. I don't like polluting my system with npm packages that I only need for one particular project, and I like to pin tools to known-good versions in my projects. |
Note that I did use |
Doing the same and absoluty agree. I understand that for better UX we should install it globally like every npm package does. However, we don't prevent users to download a GitHub release or use cargo.
I'm not familiar enought with npm's postinstall, I need to do some research. |
@kentonv The same is happening on Mac. I created a temporary project folder and installed wrangler. I didn't use sudo and node install-wrangler.js went through without any errors. a .wrangler folder in the user root directory was created.
The instructions in Cloudflare say to confirm that Wrangler has successfully installed on your machine, run
You should see the files installed in |
running npm install with sudo is not recommended (source: used to work at npm, owned the docs around this) the way to solve this (as recommended by npm) is to install node using a version manager. this will create your global node_modules directory in a user directory which prevents the need to run as root. i would recommend using OS pkg managers unfortunately do a bad job of this installation. this has been a longtime struggle in the node world. you can read more about this at https://www.npmjs.com/get-npm if this doesn't work- please follow up! (i understand this is a pain and i know that the node community has long struggled with this, long term, beyond this bug, using a node version manager is by far the better experience, so it is worth it, regardless of your feeling on this issue.) |
we can improve the docs here. i know that our readme currently recommends |
I see. I think the best practices around node and npm have changed many times over the years, and people like me who don't use them every day have trouble keeping up. I was aware of nvm but didn't realize that it's now assumed that everyone is using it... |
@kentonv yeah- very sorry about that. we should do a better job of explaining. sorry about that! and i'll make sure we prioritize this. |
Probably not best practice but I ran |
Try this : |
@magicfredo - Thanks! |
The installation process completed successfully but whenever I try to run wrangler: /usr/lib/node_modules/@cloudflare/wrangler/node_modules/binary-install/src/binary.js:60
throw `You have not installed ${this.name ? this.name : "this package"}`;
^
You have not installed wrangler
(Use `node --trace-uncaught ...` to show where the exception was thrown) |
Same issue when running in node:latest Docker container (GitLab CI/CD), without sudo. Works with @magicfredo suggestion. |
It installs "successfully" on newest Fedora and wrangler than throwing
|
`istiyak@istiyak-amin:/var/www/html/cf-worker$ wrangler --help /usr/lib/node_modules/@cloudflare/wrangler/node_modules/binary-install/src/binary.js:60 ` The same issue happened also for me |
npm didn't work for me, but using yarn worked. |
It seems like the repo's README has been updated, but not the main 'Getting Started' webpage, which doesn't mention this issue at all. |
try this |
I got the exact issue, but after I updated |
Hi, Open terminal and paste the following codes. Use nano editor Paste the following codes at the bottom => .bashrc Finally Hope this helps. Happy coding.... |
This error still occur as at 6 Sep 2021 just trying to install wrangler into the official node container. #848 did not seem to address it. How to recreate: Dockerfile
Command: Error:
|
Why even does the readme tell everybody to install wrangler globally when this is obviously not what most setups require? Just remove the |
If you guys are macOS users (Monterey v12.1) ... i tried many solutions this works for me by @younggrandpa 👍🏻 |
https://workers.cloudflare.com says to use
npm install -g @cloudflare/wrangler
to install, but on Linux that doesn't work because only root can perform global installs. The usual thing to do is putsudo
in front of it, but that doesn't work either, producing the log shown below.It appears the problem is that Wrangler's post-install script is trying to put stuff in the user's home directory. Fundamentally,
install -g
shouldn't be doing any per-user stuff; the whole point is to install for all users. The permission error seems to occur because whennpm install
is run as root, it actually runs the post-install script asnobody
. This seems... bizarre, since I'm not sure what a post-install script could usefully do when running asnobody
, but there you go. In any case,homedir()
still returns/root
(despite the active user beingnobody
), and of coursenobody
cannot access/root
, hence the permissions error.But even if the post-install script did run as root, it seems that Wrangler would end up installing files into the root user's home directory, where they would be inaccessible to any other user and thus not very useful.
Non-global installs appear work, with the caveat that the wrangler binary gets placed in
$HOME/.wrangler
with no versioning, so separate projects depending on different versions of Wrangler will interfere with each other. IMO it would be better to place the binary somewhere under the module's installation location innode_modules
.The text was updated successfully, but these errors were encountered: