Hi, I’m trying to follow the tutorial:
Everything seemed to move along just fine, until I test the cloud/getCoffee function. When I do that, I get the above error.
I have to add though, I don’t get it 100% of the time. For a while, it appeared that if I modify (like adding/removing a blank line) & save the function form the Digital Ocean page, it would work, but as soon as I deploy it from doctl, I’d get the error again. That was a couple hours ago. Now that I’m back at it, I can’t get it working properly at all. I suspect if I keep goofing with it though, I may get some intermittent success. I haven’t nailed down the specifics to reliably reproduce the problem.
I have a scripting background, some minor web app development, but no experience with NodeJS/Mongo/Cloud. That’s why I’m messing with the tutorial.
Activation Id: 32a38503a25641e6a38503a25651e600 2022-09-18T17:48:44.171377073Z stdout: ReferenceError: require is not defined in ES module scope, you can use import instead 2022-09-18T17:48:44.171455712Z stdout: at file:///tmp/index.mjs:2:21 2022-09-18T17:48:44.171463273Z stdout: at ModuleJob.run (internal/modules/esm/module_job.js:183:25) 2022-09-18T17:48:44.171467211Z stdout: at async Loader.import (internal/modules/esm/loader.js:178:24) 2022-09-18T17:48:44.171470901Z stdout: at async actionLoop (/nodejsAction/prelauncher.js:68:20) 2022-09-18T17:48:44.174519Z stderr: The action did not initialize or run as expected. Log data might be missing.
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.
Click below to sign up and get $200 of credit to try our products over 60 days!
I was able to fix this by changing the function’s runtime from Node 14 (the current default) to Node 18.
You can do that by defining
nodejs:18as the function’s runtime:
You can also do it in the web interface of the function’s settings, but if you deploy again from the commandline this is overwritten with what’s defined in
Here are the docs on available runtimes: https://docs.digitalocean.com/products/functions/reference/runtimes/
Does it work with
doctlif you try to add the
As a reference, the URL to the tutorial has been updated to: