Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling for ESM (type="module") packages #68

Merged
merged 1 commit into from
Jun 25, 2022

Conversation

thescientist13
Copy link
Member

Related Issue

#67

Found this issue when using in https://github.com/ProjectEvergreen/eleventy-plugin-wcc

% npm run demo

> [email protected] demo
> npm run build -- --serve


> [email protected] build
> npm run clean && eleventy "--serve"


> [email protected] clean
> rimraf ./_site

[11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
[11ty] 1. Error in your Eleventy config file '/Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/.eleventy.js'. (via EleventyConfigError)
[11ty] 2. Must use import to load ES Module: /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/dist/wcc.dist.js
[11ty] require() of ES modules is not supported.
[11ty] require() of /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/dist/wcc.dist.js from /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
[11ty] Instead rename wcc.dist.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/package.json. (via Error)
[11ty]
[11ty] Original error stack trace: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/dist/wcc.dist.js
[11ty] require() of ES modules is not supported.
[11ty] require() of /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/dist/wcc.dist.js from /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
[11ty] Instead rename wcc.dist.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/node_modules/wc-compiler/package.json.
[11ty]
[11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1085:13)
[11ty]     at Module.load (internal/modules/cjs/loader.js:933:32)
[11ty]     at Function.Module._load (internal/modules/cjs/loader.js:774:14)
[11ty]     at Module.require (internal/modules/cjs/loader.js:957:19)
[11ty]     at require (internal/modules/cjs/helpers.js:88:18)
[11ty]     at Object.<anonymous> (/Users/owenbuckley/Workspace/project-evergreen/repos/eleventy-plugin-wcc/src/index.js:1:28)
[11ty]     at Module._compile (internal/modules/cjs/loader.js:1068:30)
[11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
[11ty]     at Module.load (internal/modules/cjs/loader.js:933:32)
[11ty]     at Function.Module._load (internal/modules/cjs/loader.js:774:14)

Summary of Changes

  1. Specified file extension specifically as .cjs
  2. Updated README.md and package.json accordingly

@thescientist13 thescientist13 added bug Something isn't working p0 labels Jun 25, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Jun 25, 2022
@thescientist13 thescientist13 self-assigned this Jun 25, 2022
@thescientist13 thescientist13 changed the title handling for type module packages handling for ESM (`type="module") packages Jun 25, 2022
@thescientist13 thescientist13 changed the title handling for ESM (`type="module") packages handling for ESM (type="module") packages Jun 25, 2022
@thescientist13 thescientist13 merged commit 1f71864 into master Jun 25, 2022
@thescientist13 thescientist13 deleted the bug/fix-type-module-interop branch June 25, 2022 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p0 v0.4.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant