module: warn on require of .js inside type: module
This is a follow-up to the PR made in https://github.com/nodejs/node/pull/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), orvcbuild test
(Windows) passes -
commit message follows commit guidelines