Skip to content

Support for ES Modules #2891

Open
Open
@gilgardosh

Description

@gilgardosh

Describe the bug
Mesh errors on build once package.json contains "type": "module

Failed to generate schema: require() of ES Module .../graphql-mesh/examples/odata-msgraph-programmatic/.mesh/sources/Microsoft Graph/metadata.json.js from .../graphql-mesh/examples/odata-msgraph-programmatic/node_modules/@graphql-mesh/cli/bin.js not supported.
metadata.json.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename metadata.json.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in .../graphql-mesh/examples/odata-msgraph-programmatic/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

To Reproduce
Steps to reproduce the behavior:

  1. Take an example from the repo, such as odata-msgraph-programmatic.
  2. Add "type": "module" to the package.json
  3. run mesh build
  4. error thrown

Expected behavior
Build with no issues :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions