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

esm: clarify ERR_REQUIRE_ESM errors #49521

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

danielcompton
Copy link
Contributor

@danielcompton danielcompton commented Sep 6, 2023

In #39175, better ESM errors were introduced. This commit tweaks the language in the error slightly to make it clear that there are three different options to resolve the error.

I find the current message more difficult to parse, because you only realise that you need to pick one of the three options after reading most of the (very long) sentence. Putting "either" at the start of the message should signpost that these are three options and you can pick any of them.

Before

[Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/me/Developer/company/repo/app/src/tracer.js not supported.
tracer.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 tracer.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 /Users/me/Developer/company/repo/app/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

After

[Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/me/Developer/company/repo/app/src/tracer.js not supported.
tracer.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 either rename tracer.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 /Users/me/Developer/company/repo/app/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

In nodejs#39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: nodejs#39175
@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run. labels Sep 6, 2023
@lpinca
Copy link
Member

lpinca commented Sep 13, 2023

cc: @nodejs/loaders

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Sep 13, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 13, 2023
@nodejs-github-bot
Copy link
Collaborator

@GeoffreyBooth GeoffreyBooth added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Sep 14, 2023
@GeoffreyBooth GeoffreyBooth added the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 15, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 15, 2023
@nodejs-github-bot nodejs-github-bot merged commit 6a489df into nodejs:main Sep 15, 2023
33 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 6a489df

ruyadorno pushed a commit that referenced this pull request Sep 28, 2023
In #39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: #39175
PR-URL: #49521
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
This was referenced Sep 28, 2023
alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
In nodejs#39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: nodejs#39175
PR-URL: nodejs#49521
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
targos pushed a commit to targos/node that referenced this pull request Nov 11, 2023
In nodejs#39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: nodejs#39175
PR-URL: nodejs#49521
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
@targos targos added the backported-to-v18.x PRs backported to the v18.x-staging branch. label Nov 23, 2023
targos pushed a commit that referenced this pull request Nov 23, 2023
In #39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: #39175
PR-URL: #49521
Backport-PR-URL: #50669
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
In #39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: nodejs/node#39175
PR-URL: nodejs/node#49521
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
In #39175, better ESM errors were introduced. This commit tweaks the
language in the error slightly to make it clear that there are three
different options to resolve the error.

Refs: nodejs/node#39175
PR-URL: nodejs/node#49521
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backported-to-v18.x PRs backported to the v18.x-staging branch. errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants