Can't load ESM modules in config

Open
#3,003 12 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript

Research direction

Reproduce the failure from a stencil.config.ts that imports and uses globby@12, then inspect how the Stencil config is loaded. Confirm the build succeeds when an ESM module is imported from the config without the ERR_REQUIRE_ESM failure.

Written by the indexing model from the issue text.

Description

Resolution: Refine

Stencil version:

 @stencil/core@2.6.0

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

When trying to import a ESM module in the config file (in my example, globby), the build fails with:

[ ERROR ]  Error [ERR_REQUIRE_ESM]: require() of ES Module
           C:\Git\PolicyStaging.WebComponents\node_modules\globby\index.js from
           C:\Git\PolicyStaging.WebComponents\build\stencil\icu\gen\dts.ts not supported. Instead change the require of
           index.js in C:\Git\PolicyStaging.WebComponents\build\stencil\icu\gen\dts.ts to a dynamic import() which is
           available in all CommonJS modules.

Expected behavior:

The build should work as expected.

Steps to reproduce:

Create a stencil.config.ts, import and use globby@12 from it.

Dominant language
TypeScript
Stars
13.1k
Forks
855
Avg merge
4h 7m
Merged PRs (30d)
44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stenciljs/core

All issues in stenciljs/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.