Report this

What is the reason for this report?

Followed all info I could find, getting 'npm: command not found'?

Posted on July 5, 2022

Just to be thorough, I’ll dump every minimal step I did to encounter this problem:

  1. I start a completely fresh serverless project:
    1. doctl serverless init --language js sandbox4
  2. I run the project to test that it works:
    1. doctl serverless deploy sandbox4
    2. it works, it’s deployed and I can see it in the web GUI. 🎉
  3. I add a single dependency, (in this case mongodb)
    1. cd sandbox4/packages/sample/hello
    2. npm init -y (generate a package.json for the function package)
    3. npm install --package-lock-only mongodb
  4. I go back to the same directory and re-run the deploy command
    1. cd ../../../..
    2. doctl serverless deploy sandbox4
  5. it fails with the following:
Deploying '/home/j/doctl/sandbox4'
  to namespace 'fn-52e42936-046c-46fb-bf57-2cd06f2ddbe2'
  on host 'https://faas-ams3-2a2df116.doserverless.co'
Started running npm install --production in /home/j/doctl/sandbox4/sample/hello
Output of failed build in /home/j/doctl/sandbox4/packages/sample/hello
/bin/bash: npm: command not found


Failures:
Error: While deploying action 'sample/hello': 'npm install' exited with code 127

I have so many questions:

  • am I using the wrong runtime? (it’s currently nodejs:default)
  • did I structure my project wrongly?

Currently it looks like this:

➜  doctl tree sandbox4 -a
sandbox4
├── .deployed
│   └── versions.json
├── .gitignore
├── packages
│   └── sample
│       └── hello
│           ├── hello.js
│           ├── package.json
│           └── package-lock.json
└── project.yml

4 directories, 6 files
➜  doctl 


and the only content that should look any different from the auto-generated sample files is the package.json (and its lock file), it looks like this:

➜  doctl cat sandbox4/packages/sample/hello/package.json 
{
  "dependencies": {
    "mongodb": "^4.7.0"
  }
}

  • can I get more verbose error output somehow? I want more information!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.