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.
heroku@f81dbaa99df8:/workspace$ cd server
heroku@f81dbaa99df8:/workspace/server$ npm run migration:run
bash: npm: command not found
heroku@f81dbaa99df8:/workspace$ cd server
heroku@f81dbaa99df8:/workspace/server$ npm run migration:run
bash: npm: command not found
13 Replies
Siumauricio
Siumauricio•9mo ago
the /server folder have the package.json?
predragnikolic
predragnikolicOP•9mo ago
yes
Siumauricio
Siumauricio•9mo ago
Can you share the package.json
predragnikolic
predragnikolicOP•9mo ago
here it is, nothing sensitive in it
predragnikolic
predragnikolicOP•9mo ago
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.
Siumauricio
Siumauricio•9mo ago
Hmm also based on the first message you are running the migrations, why you didn’t run in the start command?
predragnikolic
predragnikolicOP•9mo ago
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 terminal
Siumauricio
Siumauricio•9mo ago
Have you tried nixpacks? Probably the node image is not available in the final image using heroku 🤔
predragnikolic
predragnikolicOP•9mo ago
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:
{
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
{
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
Dokploy uses a command pack that builds the Heroku container:
await spawnAsync("pack", [
"build",
appName,
"--path",
buildAppDirectory,
"--builder",
"heroku/builder:24",
], (data) => {
});
...
await spawnAsync("pack", [
"build",
appName,
"--path",
buildAppDirectory,
"--builder",
"heroku/builder:24",
], (data) => {
});
...
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?
Siumauricio
Siumauricio•9mo ago
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.
predragnikolic
predragnikolicOP•9mo ago
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.
predragnikolic
predragnikolicOP•9mo ago
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. 🙂
predragnikolic
predragnikolicOP•9mo ago
GitHub
Issues · heroku/cnb-builder-images
Recipes for building Heroku's Cloud Native Buildpacks builder images - Issues · heroku/cnb-builder-images

Did you find this page helpful?