I am trying to install wrangler inside a Docker container using the NPM -g flag. The Node was installed inside the container using NVM.
rustc -V:node -v: v13.0.1wrangler -V:Start an Ubuntu container:
docker run -it ubuntu
You will get inside the bash of that container.
Install curl:
apt-get update && apt-get install curl
Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
Load NVM:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Install a node version:
nvm install stable
Install wrangler:
npm i -g @cloudflare/wrangler
I was hoping wrangler would get installed.
> @cloudflare/[email protected] postinstall /root/.nvm/versions/node/v13.0.1/lib/node_modules/@cloudflare/wrangler
> node install-wrangler.js
sh: 1: node: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @cloudflare/[email protected] postinstall: `node install-wrangler.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the @cloudflare/[email protected] 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! /root/.npm/_logs/2019-10-24T20_07_14_640Z-debug.log
Hey @dompuiu, I did something similar recently with the wrangler GitHub action integration we just launched:
https://github.com/cloudflare/wrangler-action/blob/master/entrypoint.sh
Maybe that'd be helpful? FWIW, I think those containers run with a user github so maybe the root part here would cause the instructions to differ a bit. Other folks on the team might know more about that than me 馃槵
I've tried to use some commands from that file. But I was still not able to make it work.
As a side note, I tried also installing node using the following commands (so no NVM):
apt-get update && apt-get -y install curl
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get -y install nodejs
With the node installed this way I get a different error:
Error: EACCES: permission denied, mkdir '/root/.wrangler'
at mkdirSync (fs.js:823:3)
at Object.<anonymous> (/usr/lib/node_modules/@cloudflare/wrangler/install-wrangler.js:58:3)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11 {
errno: -13,
syscall: 'mkdir',
code: 'EACCES',
path: '/root/.wrangler'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @cloudflare/[email protected] postinstall: `node install-wrangler.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @cloudflare/[email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Even if I create the $HOME/.wrangler folder with 777, I still get the same error. Maybe you should check to see if the .wrangler folder exists before calling the mkdir command.
I've been unable to install on MacOSX for months. Block by the same issue. Running as sudo. Re-installed node & npm.
Error: EACCES: permission denied, mkdir '/Users/user1/.wrangler'
Even if I create all the directories manually the script tries to create them iself instead of checking first and fails.
@bladerunner41 Unfortunately, EACCES errors are not something we can fix in Wrangler as it's a product of the node ecosystem. We recommend using nvm, but there are alternative solutions outlined here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
For @dompuiu, I'd maybe try running nvm use stable in the same directory that you're trying to install wrangler from, and also making sure that which nvm points to a .nvm directory. If that doesn't work, I'd recommend installing with cargo install wrangler
Hey @dompuiu! I think you were actually _very_ close to getting this working in your initial bug report. As per the README, we recommend installing Wrangler via NVM or a similar Node package manager, as it should simplify any potential permissions issues.
In your original bug report, it seems like things work until you get to installing Wrangler. In my GitHub action code, I set the WRANGLER_HOME directory, to make sure that wrangler installs into a known directory with good permissions. Here's what I did:
export HOME="/github/workspace"
export NVM_DIR="/github/workspace/nvm"
export WRANGLER_HOME="/github/workspace"
mkdir -p "$HOME/.wrangler"
chmod -R 770 "$HOME/.wrangler"
FWIW, I'd also make sure that whenever you're using npm, such as npm install -g @cloudflare/wrangler, be sure that you're not using sudo! Doing so will mess up the permissions for your NPM packages and would definitely cause an error here.
@signalnerve I was able to make it work using some of the steps you provided. Thanks!
For anyone interested these are the steps that I run inside the ubuntu container:
apt-get update && apt-get install -y curl
mkdir github
export HOME="/github"
mkdir -p "$HOME/.wrangler"
chmod -R 770 "$HOME/.wrangler"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install stable
npm i -g @cloudflare/wrangler
My real setup is more complicated, but I will be able to make it work.
I think the lesson is that you cannot install the wrangler tool as root using the default HOME directory.
Ah, exciting that you got it working! Please let us know if there's anything in particular you think we should do to make documentation around this better. Thanks @dompuiu!
i think this issue is now resolved- so i am going to close! i do think we should better document these features- and have filed this issue to track that work: https://github.com/cloudflare/workers-docs/issues/481 thanks everyone!
Apologies for re-opening this, however I came across this issue and the above steps didn't work (for my node environment, not ubuntu) - however for future readers, the following worked for me:
FROM node:12.13.0
WORKDIR /app
COPY package.json package.json
RUN npm i -g @cloudflare/wrangler --unsafe-perm=true --allow-root
RUN npm i
RUN wrangler --version
thx @blackn1ght soved my problem.
Fixing my npm following did work.
@blackn1ght you legend! I've been trying to crack this for hours. This is what did the trick for me
@signalnerve I was able to make it work using some of the steps you provided. Thanks!
For anyone interested these are the steps that I run inside the ubuntu container:
apt-get update && apt-get install -y curl mkdir github export HOME="/github" mkdir -p "$HOME/.wrangler" chmod -R 770 "$HOME/.wrangler" curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm install stable npm i -g @cloudflare/wranglerMy real setup is more complicated, but I will be able to make it work.
I think the lesson is that you cannot install the wrangler tool as root using the default HOME directory.
This saved me. Thanks @dompuiu
I was having problem with postscript execution while installing nodejs via apt-get at wrangler installation. I am assuming this to be some kind of wrangler bug which I cannot figure out exactly. Also tried cargo and failed in an epic way even after successful build.
Finally I found this code while searching for solution here.
Following is for people like me who have hard time installing wrangler in Ubuntu
I made some tweak for myself. I am using Ubuntu 18.04 LTS
sudo apt-get update
sudo apt-get upgrade
mkdir -p "$HOME/.wrangler"
chmod -R 770 "$HOME/.wrangler"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install stable
npm i -g npm
npm i -g @cloudflare/wrangler
node -v && npm -v && wrangler -V
Resulted in:
v14.2.0
6.14.5
wrangler 1.8.4
solutions outlined here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
also making sure that
which nvmpoints to a.nvmdirectory.
there is no which nvm only command -v nvm Zuul
Quoting from: https://github.com/nvm-sh/nvm#verify-installation
Please note that which nvm will not work, since nvm is a sourced shell function, not an executable binary.
@rochapablo You fixed my issue after a few hours of getting frustrated. Thanks!
Most helpful comment
Apologies for re-opening this, however I came across this issue and the above steps didn't work (for my node environment, not ubuntu) - however for future readers, the following worked for me: