NPM is ignoring packages directory for functions.


I am following the functions tutorial at: together with the sample project: .

I have run into the same problem with the tutorial as with the sample project, but I will explain the issue in terms of sample project so that it can be replicated.

When it comes to executing: doctl serverless deploy ., I get this error:

Deploying '/home/user/Files/serverless2/sample-functions-nodejs-qrcode'
  to namespace 'fn-xxx'
  on host ''
Started running npm install --production in /home/user/Files/serverless2/sample-functions-nodejs-qrcode/qr/qr
Output of failed build in /home/user/Files/serverless2/sample-functions-nodejs-qrcode/packages/qr/qr
/bin/bash: npm: command not found

Error: While deploying action 'qr/qr': 'npm install' exited with code 127

I have the latest version of Node (v18.7.0) and NPM (8.15.0) installed.

I don’t quite understand why it outputs /bin/bash: npm: command not found because I get a proper version when I execute node -v and npm -v.

I have noticed that the command executed by doctl skips the packages directory and instead goes directly to sample-functions-nodejs-qrcode/qr/qr (instead of sample-functions-nodejs-qrcode/packages/qr/qr).

Does anyone know how to fix this?


Submit an answer
Answer a question...

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.

Bobby Iliev
Site Moderator
Site Moderator badge
August 4, 2022

Hi there,

What you could do is to add --remote-build. That way the function will be built on the DigitalOcean infrastructure rather than locally on your laptop.

The npm not found is most likely due to the fact that your npm installation not being added to your PATH. You can check that by running which npm.

Let me know how it goes!