Nodejs Function import module error

I have been trying for the last 5 days to get a simple function to work. Not even the demo examples work and at this point, I think the issue is with DigitalOcean. I am using a Nodejs function to output a string. I try using import a module and this is the error I get: " Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘parse-domain’ imported from /tmp/index.mjs". So I try to change it to require and get this error: “ReferenceError: require is not defined in ES module scope, you can use import instead”. I am using “doctl serverless deploy . --remote-build” in the same directory as the project.yml. I added “type”: “module” in the package.json as well. I have the dependencies listed in there as well. I also ran npm install --package-lock-only parse-domain which didn’t work. I have module.exports.main = checkURL (function name) at the end. There is little to no documentation around DO functions and nodejs other than the examples which again doesn’t even work because I get the same error.

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.

Accepted Answer

Hey Bobby,

Thanks for responding! I did confirm doctl is up to date. The API token I’m using has both read and write permissions. Here is the repo I am using to test:

If you do come across something please let me know!

I too have been experiencing this issue with both Python and Node functions. I’m highly disappointed as I love DO products but functions seem to be a big fail on DO part right now.

I wish I could offer some solution but there’s literally no helpful documentation on this. It also took forever to figure out how to switch function namespaces and I’m still confused on how exactly it should be done. Super frustrating.

Bobby Iliev
Site Moderator
Site Moderator badge
February 25, 2023

Hi there,

I’ve just tried deploying one of the example Node.js serverless functions and it seems to be working as expected.

Can you confirm the following:

  • Make sure you have the latest version of doctl installed on your local machine.
  • Verify that your API token has write permissions so that the deployment could work as intended.
  • Can you share the repo containing your serverless function so I could try to have a look and identify any issues that might be causing the problem?



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel