Question

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

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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

I’ve just tried this out and it seems to all be working as expected.

I’ve created a demo project with the exact same steps as you:

https://github.com/bobbyiliev/serverless-hello-wolrd-node

Would you mind trying to run this and let me know if you are still seeing the issue:

  • Clone the repo:
git clone https://github.com/bobbyiliev/serverless-hello-wolrd-node.git
  • Deploy the project:
doctl serverless deploy serverless-hello-wolrd-node
  • Invoke the function:
doctl serverless functions invoke sample/hello

EDIT: I’ve just received some feedback from our FaaS team, in order for your function to be built remotely, you need to specify the --remote-build flag.

Alternatively, you need to install npm locally so that the build could succeed on your local machine too.

Let me know how it goes!

Best,

Bobby

This comment has been deleted