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

module: warn on require of .js inside type: module #29909

Closed
wants to merge 3 commits into from

Conversation

@guybedford
Copy link
Contributor

guybedford commented Oct 9, 2019

This is a follow-up to the PR made in #29732 ensuring a warning is emitted when violating the "type": "module" expected module format.

This was discussed at today's modules group meeting as a starting point for handling this case, and then whether or not an error will be thrown when modules are unflagged is still to be discussed further.

Example output:

(node:28347) Warning: require() of ES modules is not supported.
require() of /home/guybedford/Projects/node/test/fixtures/es-modules/package-type-module/cjs.js from /home/guybedford/Projects/node/test/fixtures/es-modules/cjs-esm.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.
Instead rename cjs.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/guybedford/Projects/node/test/fixtures/es-modules/package-type-module/package.json.

@nodejs/modules-active-members

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
@jkrems
jkrems approved these changes Oct 9, 2019
Copy link
Contributor

jkrems left a comment

LGTM

@guybedford guybedford added ES Modules and removed author ready labels Oct 10, 2019
@guybedford guybedford force-pushed the guybedford:type-module-cjs-warn branch from dba91d0 to 38554bc Oct 10, 2019
@guybedford guybedford mentioned this pull request Oct 11, 2019
3 of 4 tasks complete
@nodejs-github-bot

This comment has been minimized.

@guybedford guybedford force-pushed the guybedford:type-module-cjs-warn branch from 38554bc to 9153981 Oct 11, 2019
@nodejs-github-bot

This comment has been minimized.

@guybedford guybedford mentioned this pull request Oct 11, 2019
2 of 2 tasks complete
@jkrems

This comment has been minimized.

Copy link
Contributor

jkrems commented Oct 11, 2019

Revised message SGTM!

guybedford added a commit that referenced this pull request Oct 11, 2019
PR-URL: #29909
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@guybedford

This comment has been minimized.

Copy link
Contributor Author

guybedford commented Oct 11, 2019

Landed in aca1c28.

@guybedford guybedford closed this Oct 11, 2019
targos added a commit that referenced this pull request Nov 8, 2019
PR-URL: #29909
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
targos added a commit that referenced this pull request Nov 10, 2019
PR-URL: #29909
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.