Skip to content

Commit 2825e11

Browse files
guybedfordTrott
authored andcommitted
module: move cjs type check behind flag
PR-URL: #29732 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
1 parent f21818e commit 2825e11

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ Module.prototype._compile = function(content, filename) {
953953

954954
// Native extension for .js
955955
Module._extensions['.js'] = function(module, filename) {
956-
if (filename.endsWith('.js')) {
956+
if (experimentalModules && filename.endsWith('.js')) {
957957
const pkg = readPackageScope(filename);
958958
if (pkg && pkg.type === 'module') {
959959
throw new ERR_REQUIRE_ESM(filename);

test/es-module/test-esm-type-flag-errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-modules
12
'use strict';
23
const common = require('../common');
34
const assert = require('assert');

0 commit comments

Comments
 (0)