Just to be thorough, I’ll dump every minimal step I did to encounter this problem:
doctl serverless init --language js sandbox4
doctl serverless deploy sandbox4
cd sandbox4/packages/sample/hello
npm init -y
(generate a package.json for the function package)npm install --package-lock-only mongodb
cd ../../../..
doctl serverless deploy sandbox4
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:
nodejs:default
)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"
}
}
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!
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.
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:
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
I encountered the exact same error. Read the output message with care, and you can the deploy is trying to run npm on your local machine, and your npm is not in its $PATH envoirment.
On my machine, that was caused by install node via nvm. Thus adding a link of your npm cli to /usr/local/bin should fix this issue.