Question

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: https://github.com/SevenGuru/DO_Functions.

If you do come across something please let me know!

Nothing listed in the website, or even docs was not helpful. No matter what I do, I get the same error as the OP. I ended up switching to another platform.

This is the doc I referred to : https://docs.digitalocean.com/products/functions/reference/runtimes/node-js/#handle-native-dependencies

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.

Try DigitalOcean for free

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

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.