Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to install elm packages (on debian stable) #434

Open
wibrt opened this issue Apr 24, 2020 · 15 comments
Open

Failed to install elm packages (on debian stable) #434

wibrt opened this issue Apr 24, 2020 · 15 comments

Comments

@wibrt
Copy link

wibrt commented Apr 24, 2020

Bug

after installing create-elm-app with npm

running (as user of root)

$ create-elm-app mijn-portofolie

Creating mijn-portofolie project...


Failed to install elm packages

Please, make sure you have internet connection!

In case if you are running Unix OS, you might look in to this issue:

    https://github.com/halfzebra/create-elm-app/issues/10

So there is a reference to issue 10,
all elm npm packages are installed globally

Environment

Packages are installed from debian stable if available, otherwise from npm

  1. node -v:v10.15.2
  2. npm -v:5.8.0
  3. npm ls create-elm-app -g (if you haven’t ejected):
    /usr/local/lib
    └── [email protected]

Then, specify:

  1. Operating system: Debian 10 Buster

Steps to Reproduce

  1. On debian stable
  2. install nodejs and npm package
  3. npm install -g create-elm-app
  4. create-elm-app mytest
@wibrt
Copy link
Author

wibrt commented Apr 24, 2020

Installing everythin with the newest versions available from npm for debian ({"os":"linux","arch":"x64"}) also does not work

$ npm -v
6.14.4
$ nodejs -v
v10.15.2

Dependecies:

Side note:
deprecated but used by create-elm-app:

  • resolve-url
  • request
  • urix

not supported on linux:

@wibrt
Copy link
Author

wibrt commented Apr 24, 2020

Also tried with

$ node -v
v12.16.2

(no improvement)

as to one of the reference in issue #10

/usr/local/lib/node_modules/create-elm-app/node_modules# ls el* -d
electron-to-chromium  elm-asset-webpack-loader	elmi-to-json
elliptic	      elm-hot			elm-test
elm		      elm-hot-webpack-loader	elm-webpack-loader

@halfzebra
Copy link
Owner

halfzebra commented Apr 24, 2020

Hi @wibrt!

Thanks for reporting this issue, have you tried one of those solutions suggested in #26 (comment)?

@wibrt
Copy link
Author

wibrt commented Apr 27, 2020

Yes, the install works,

$ ls /usr/local/lib/node_modules/create-elm-app/node_modules/el
electron-to-chromium/ elm-asset-webpack-loader/ elmi-to-json/
elliptic/ elm-hot/ elm-test/
elm/ elm-hot-webpack-loader/ elm-webpack-loader/

$ ls /usr/local/lib/node_modules/create-elm-app/node_modules/elm
bin download.js install.js package.json README.md

$ ll /usr/local/lib/node_modules/create-elm-app/node_modules/elm/bin/
totaal 27728
-rwxr-xr-x 1 28392488 apr 24 11:13 elm

Just to make sure i use this elm binary, the same elm version is also globally installed.

$ ./elm 
Hi, thank you for trying out Elm 0.19.1. I hope you like it!

-------------------------------------------------------------------------------
I highly recommend working through <https://guide.elm-lang.org> to get started.
It teaches many important concepts, including how to use `elm` in the terminal.
-------------------------------------------------------------------------------

The most common commands are:

    elm repl
        Open up an interactive programming session. Type in Elm expressions like
        (2 + 2) or (String.length "test") and see if they equal four!
    
    elm init
        Start an Elm project. It creates a starter elm.json file and provides a
        link explaining what to do from there.
    
    elm reactor
        Compile code with a click. It opens a file viewer in your browser, and
        when you click on an Elm file, it compiles and you see the result.

There are a bunch of other commands as well though. Here is a full list:

    elm repl    --help
    elm init    --help
    elm reactor --help
    elm make    --help
    elm install --help
    elm bump    --help
    elm diff    --help
    elm publish --help

Adding the --help flag gives a bunch of additional details about each one.

Be sure to ask on the Elm slack if you run into trouble! Folks are friendly and
happy to help out. They hang out there because it is fun, so be kind to get the
best results!
$ create-elm-app test

Creating test project...


Failed to install elm packages

Please, make sure you have internet connection!

In case if you are running Unix OS, you might look in to this issue:

    https://github.com/halfzebra/create-elm-app/issues/10

@turboMaCk
Copy link

turboMaCk commented Apr 27, 2020

In my opinion elm-create-app should avoid depending on npm installation of elm and ideally even other things that depend on binwrap (elm-test, elm-format, elmi-to-json). In nixpkgs we have custom scripts to patch create-elm-app. You can have a look into this PR for some inspiration NixOS/nixpkgs#85324

I think you might be able hotfix this on your machine by running this:

$ ln -sf $(which elm) ls /usr/local/lib/node_modules/create-elm-app/node_modules/elm/bin/elm

In addition you might need to no-op the install.js

@wibrt
Copy link
Author

wibrt commented Apr 27, 2020

For a reason that i don't understand, this works now.

An upgrade to 4.2.13 (from 4.2.11)
seemed to fix the problem.

Thank you.

@turboMaCk
Copy link

I think the problem was that install.js script for npm installation elm didin't finish successfully so create-elm-app was calling into existing nodejs wrapper but this wrapper was unable to call the binary of compiler.

@joekinley
Copy link

I still have this problem (doing this within a dockerfile).
Versions:

  • node v10.19.0
  • npm 6.13.4
  • elm 0.19.1
  • create_elm_app 5.9.0

I tried everything that came in this issue #434 as well as issue #10
Any further ideas?

@turboMaCk
Copy link

what does "this problem" mean? If you get failed to install packages check your permissions. Also saying just Dockerfile doesn't help much - are you using Debian as a base image?

@joekinley
Copy link

Okay so the Dockerfile is this

FROM alpine:3.10.2

ENV APP_HOME /app
WORKDIR $APP_HOME
VOLUME $APP_HOME

RUN apk add git nodejs npm

RUN npm install -g --unsafe-perm=true elm create-elm-app elm-format elmstatic

ENV ELM_HOME=$APP_HOME/.elm-home
RUN mkdir -p $APP_HOME/.elm-home

CMD ["sh"]

This is the output

/app # create-elm-app test

Creating test project...


Failed to install elm packages

Please, make sure you have internet connection!

In case if you are running Unix OS, you might look in to this issue:

    https://github.com/halfzebra/create-elm-app/issues/10

As the container is running as root I am not quite sure whether permissions might be a problem here. Yet I might be completely wrong.

Any pointers to further information, or tips are really appreciated.

@turboMaCk
Copy link

So this is where it fails for you:

const spawnElmPkgResult = spawn.sync(
path.resolve(__dirname, '../node_modules/.bin/elm'),
// Run elm-make to install the dependencies.
['make', 'src/Main.elm', '--output=/dev/null'],
{ stdio: 'inherit', cwd: appRoot }
);
if (spawnElmPkgResult.status !== 0) {
console.log();
console.log(chalk.red('Failed to install elm packages'));
console.log();
console.log('Please, make sure you have internet connection!');
if (!isWindows) {
console.log();
console.log(
'In case if you are running Unix OS, you might look in to this issue:'
);
console.log();
console.log(' https://github.com/halfzebra/create-elm-app/issues/10');
}
process.exit(1);
}

Things to try:

@joekinley
Copy link

So my /app folder is empty, as I want to create a new app into this, with create-elm-app.
Here is the output to npm run postinstall

/app # npm run postinstall
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-26T15_09_25_638Z-debug.log

Of course I don't have a /app/package.json.

Now about ../node_modules/.bin/elm. What is the source supposed to be here?

  • if it is /app, There is no /node_modules...
  • if it is $HOME, there is no node_modules either
  • if it is /usr/lib/.node_modules, there is no .bin in here. I created one, and symlinked like this:
/usr/lib/node_modules # ls -la .bin/
total 8
drwxr-xr-x    2 root     root          4096 Oct 26 15:11 .
drwxr-xr-x    1 root     root          4096 Oct 26 15:11 ..
lrwxrwxrwx    1 root     root            33 Oct 26 15:11 elm -> /usr/lib/node_modules/elm/bin/elm

Yet, after this neither create-elm-app nor npm run postinstall do anything different than described here.

Thank you for your help so far, if there is anything more I can do, read, or try, I'm open to everything.

@turboMaCk
Copy link

turboMaCk commented Oct 26, 2020

npm (actually node itself I believe) has rules about how it goes about resolving node modules you can check it. If you don't have local node_modules yhou need to check global ones. use npm config get prefix you can also use set prefix to set it to the location where you want to install global node modules (probably should be in PATH though). I think this is all documented -- man npm.

@joekinley
Copy link

Okay, after some parsing and figuring out, here is my solution:
This is my dockerfile now:

FROM alpine:3.10.2

# install npm and needed modules for elm
RUN apk add git nodejs npm
RUN npm install -g --unsafe-perm=true elm create-elm-app elm-format elmstatic
WORKDIR /usr/lib/node_modules/create-elm-app
RUN npm install # rerun install for create-elm-app

ENV ELM_HOME=$APP_HOME/.elm-home
RUN mkdir -p $APP_HOME/.elm-home

ENV APP_HOME /app
WORKDIR $APP_HOME
VOLUME $APP_HOME

CMD ["sh"]

So we need to go into /usr/lib/node_modules/create-elm-app and run npm install here, for the file /usr/lib/node_modules/create-elm-app/node_modules/.bin/elm to be created. So this is the ../node_modules... file that was mentioned.

It is sad that the plain npm install -g create-elm-app is not enough for everything to work, and I am not sure what the cause for this is. At least I got my result and maybe could help some other people with this.

@turboMaCk
Copy link

My guess is that for security reasons npm doesn't run post-install scripts when being run as a root. This is understandable because allowing this means that package can do anything to your system during installation.

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

No branches or pull requests

4 participants