How to run npm commands in the container
Hello I successfully build my NodeJS app with Heroku Buildpack.
Now I want to run an npm command in docker terminal, but I get an error that the npm command is not found.
13 Replies
the /server folder have the package.json?
yes
Can you share the package.json
here it is, nothing sensitive in it
So, based on your answer, I should be able to access
npm
🙂 which makes me think of what I am doing wrong. I will spend some time getting to now Dokploy. I cloned it locally just to get a better feeling.Hmm also based on the first message you are running the migrations, why you didn’t run in the start command?
I used
npm run migration:run
just as an example.
The command I actually wanted to run was npm run db:seed --name=NameOfTheSeed
Regardless if I want to run npm run db:seed ...
or npm run migration:run
, the docker terminal will print out npm: command not found
I am wondering why npm
or node
are not awailable as commands in the docker terminalHave you tried nixpacks?
Probably the node image is not available in the final image using heroku 🤔
Probably the node image is not available in the final image using heroku 🤔I would now think the same. Accessing
npm
in the bash terminal works when the app is built with Nixpacks. ✅
I did a quick search:
http://stackoverflow.com/questions/12943079/heroku-bash-node-command-not-found
https://stackoverflow.com/questions/44168899/heroku-run-npm-command-not-found
They say the answer is just specify a buildpack. In Heroku dashboard you have a UI where you can select the build pack, or the CLI heroku buildpacks:set heroku/nodejs
, or create a app.json
file that looks like this:
Dokploy uses a command pack
that builds the Heroku container:
I am not sure if the command pack
will respect the app.json
file (it looks like it wont https://github.com/heroku/cnb-builder-images/issues/26)
Do you maybe know how to set the build pack to use heroku/nodejs
and maybe forse the final image to have npm
and node
command in the final image?Have you already tried to create that app.json?
In nixpacks it automatically detects it when nixpacks.toml is created.
The heroku/builder automatically brings embedded all the builders in a single package, so you don't have to be specifying the builders.
Have you already tried to create that app.json?Yes I tried, but I still get
npm: command not found
.
---
Do you maybe know how to set the build pack to use heroku/nodejs and maybe forse the final image to have npm and node command in the final image?I was wrong with this sentence. I discovered that
npm
and node
are already in the image.
I have run find / -name npm
and find / -name node
in the docker bash terminal. (see the attached file for the output)
If I paste the following export PATH=$PATH:/layers/heroku_nodejs-engine/dist/bin
in the terminal, I will be able to run npm
and node
commands with the HerokuBuildpack.The good thing is that I finally can run
npm
and node
commands
by running export PATH=$PATH:/layers/heroku_nodejs-engine/dist/bin
first in the terminal.
The question is, can this be imporved that I do not have to do that. 🙂GitHub
Issues · heroku/cnb-builder-images
Recipes for building Heroku's Cloud Native Buildpacks builder images - Issues · heroku/cnb-builder-images