question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Right now this module doesn’t support ESM. If you try to use modules, your function will not load.

Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/timmerman/Documents/trash/esmtestff/index.js
require() of ES modules is not supported.

I believe there are a few things we need to do to allow functions using modules to be supported:

Repro

Allow modules in package.json

 "type": "module",

Use ESM import/export

/**
 * Send "Hello, World!"
 * @param req https://expressjs.com/en/api.html#req
 * @param res https://expressjs.com/en/api.html#res
 */
export const helloWorld = (req, res) => {
  res.send('Hello, World!');
};

Observe error:

Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: esmtestff/index.js
require() of ES modules is not supported.

Solution

Here’s the rough solution I think, after prototyping a bit:

CC: @bcoe

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
neilstuartcraigcommented, May 12, 2021

Just adding my +1 to this as it’s currently preventing me using ES modules in Cloud Functions (not firebase). I’d be happy to contribute if that’s useful.

4reactions
mbleighcommented, May 3, 2021

Hey folks, just wanted to provide a nudge and a backlink to https://github.com/firebase/firebase-tools/issues/2994 – on the Firebase side we have 50+ developers 👍 requesting ESM support. We can’t add it for Firebase until it gets added for FF, so if it’s possible to make progress that would be great for our users!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does it take to support Node.js ESM? – The Guild
I have worked on all The Guild's libraries and graphql-js to support ESM. Here is how you can do it too.
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and ... Caveat: The ESM load hook and namespaced exports from CommonJS modules...
Read more >
Getting Started with (and Surviving) Node.js ESM
The Node.js ecosystem is shifting towards ESM. We examine what lies in store for application and library authors, learn some of challenges ...
Read more >
Pure ESM package - gists · GitHub
ESM is natively supported by Node.js 12 and later. My repos are not the place to ask ESM/TypeScript/Webpack/Jest/ts-node/CRA support questions.
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
For the last few years, Node.js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found