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

npm: command not found #906

Open
predragnikolic opened this issue Aug 7, 2024 · 3 comments
Open

npm: command not found #906

predragnikolic opened this issue Aug 7, 2024 · 3 comments

Comments

@predragnikolic
Copy link

Hello 👋 ,

Given a simple NodeJS project like this:
node-example.zip

When you unzip it,
cd ./node-example and run pack build --builder heroku/builder:24 my-hello.
After the image is created, when you run the docker image, and go to the Docker bash terminal.

When I run npm run hello,
I expect the npm (and node) bin executables to be available in the $PATH
and to see the following output: Hello
The acutal behavior is that I see npm: command not found.

Although the build image does contain npm and node bins, they are not added to the $PATH,
When I paste export PATH=$PATH:/layers/heroku_nodejs-engine/dist/bin to the docker bash terminal, I will be able to run npm and node commands.

Is there something I am missing to configure in order to have npm and node without me having to do export PATH=$PATH:/layers/heroku_nodejs-engine/dist/bin

@edmorley edmorley transferred this issue from heroku/cnb-builder-images Aug 7, 2024
@edmorley
Copy link
Member

edmorley commented Aug 7, 2024

@predragnikolic Hi! I've transferred this issue to the Node.js CNB GitHub repo. The Node.js owner @colincasey will take a look at this at some point - though in the meantime I would suggest the first thing to try is that you are invoking a shell via the launcher (which depending on the buildpack setup might be the default if no process type is configured):
https://buildpacks.io/docs/for-app-developers/how-to/build-outputs/specify-launch-process/

@predragnikolic
Copy link
Author

Thanks for the quick reply @edmorley.
When running docker run --rm --entrypoint launcher -it my-hello bash I am able to access npm and node from bash.

(I will probably write something that doesn't make sense, excuse me)
Is there a way to embed the entrypoint to the docker image itself, like have ENTRYPOINT ["launcher"] in the generated docerfile?
What I would like to achieve is to build a project with pack build my-hello --builder heroku/builder:24, start the image, open a terminal in the container and access npm and node commands without having to worry about --entrypoint launcher.

I am pretty sure it is possible, I just do not know the how part.

@edmorley
Copy link
Member

edmorley commented Aug 7, 2024

So I think the UX can be improved for the Node.js buildpack if it wraps the default process it sets with bash -c. Currently the Node.js buildpack does not do this:
https://github.com/search?q=repo%3Aheroku%2Fbuildpacks-nodejs%20process_type&type=code

Compare to what the Procfile CNB does (which is what gets used if an app has a Procfile, and will override the Node.js CNB's defaults):
https://github.com/heroku/buildpacks-procfile/blob/798f602616353c15d6068e4b8ab29d164fe8a1cf/src/launch.rs#L16-L20

And as I write this, I've just remembered this UX issue also came up here:
heroku/buildpacks#15

cc @schneems

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

2 participants