Skip to content

Support ESM #233

@grant

Description

@grant

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions