Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Unable to install wrangler globally inside a Docker container when I have root access. #803

Closed
dompuiu opened this issue Oct 24, 2019 · 16 comments

Comments

@dompuiu
Copy link

dompuiu commented Oct 24, 2019

🐛 Bug Report

I am trying to install wrangler inside a Docker container using the NPM -g flag. The Node was installed inside the container using NVM.

Environment

  • operating system: Ubuntu 18.04
  • output of rustc -V:
  • output of node -v: v13.0.1
  • output of wrangler -V:

Steps to reproduce

  1. You need to have docker install on your machine.

  2. Start an Ubuntu container:

    docker run -it ubuntu
    

    You will get inside the bash of that container.

  3. Install curl:

    apt-get update && apt-get install curl
    
  4. Install NVM:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
    
  5. 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
    
  6. Install a node version:

    nvm install stable
    
  7. Install wrangler:

    npm i -g @cloudflare/wrangler
    

What did you expect to see?

I was hoping wrangler would get installed.

What did you see instead?

> @cloudflare/wrangler@1.4.0 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/wrangler@1.4.0 postinstall: `node install-wrangler.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the @cloudflare/wrangler@1.4.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!     /root/.npm/_logs/2019-10-24T20_07_14_640Z-debug.log
@kristianfreeman
Copy link
Contributor

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 😬

@dompuiu
Copy link
Author

dompuiu commented Oct 24, 2019

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/wrangler@1.4.0 postinstall: `node install-wrangler.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @cloudflare/wrangler@1.4.0 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.

@murraybauer
Copy link

murraybauer commented Oct 25, 2019

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.

@EverlastingBugstopper
Copy link
Contributor

EverlastingBugstopper commented Oct 25, 2019

@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

@kristianfreeman
Copy link
Contributor

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.

@dompuiu
Copy link
Author

dompuiu commented Oct 25, 2019

@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.

@kristianfreeman
Copy link
Contributor

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!

@ashleygwilliams
Copy link
Contributor

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: cloudflare/workers-docs#481 thanks everyone!

@blackn1ght
Copy link

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

@murraybauer
Copy link

thx @blackn1ght soved my problem.

@rochapablo
Copy link

rochapablo commented Nov 19, 2019

Fixing my npm following did work.

@abury
Copy link

abury commented Apr 1, 2020

@blackn1ght you legend! I've been trying to crack this for hours. This is what did the trick for me

@nikhiljohn10
Copy link

@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.

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

@JasonCoombs
Copy link
Contributor

solutions outlined here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

also making sure that which nvm points to a .nvm directory.

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.

@gstotts
Copy link

gstotts commented Sep 19, 2020

@rochapablo You fixed my issue after a few hours of getting frustrated. Thanks!

@nicovigil1
Copy link

Adding this here as it was the first result when I googled my error:

If none of the above works for anyone else using nvm, I added chown -R $(whoami) ~/.nvm before npm i -g @cloudflare/wrangler after loading the nvm.sh script & it resolved my issue

original error:

npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v15.6.0/lib/node_modules/@cloudflare/wrangler
npm ERR! command failed
npm ERR! command sh -c node ./install-wrangler.js
npm ERR! sh: node: command not found

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests