diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 5056a698b3b8cd..034938e56a2d6a 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -952,7 +952,7 @@ Module.prototype._compile = function(content, filename) { // Native extension for .js Module._extensions['.js'] = function(module, filename) { - if (filename.endsWith('.js')) { + if (experimentalModules && filename.endsWith('.js')) { const pkg = readPackageScope(filename); if (pkg && pkg.type === 'module') { throw new ERR_REQUIRE_ESM(filename); diff --git a/test/es-module/test-esm-type-flag-errors.js b/test/es-module/test-esm-type-flag-errors.js index a54a018ad9b774..8725fb62323b75 100644 --- a/test/es-module/test-esm-type-flag-errors.js +++ b/test/es-module/test-esm-type-flag-errors.js @@ -1,3 +1,4 @@ +// Flags: --experimental-modules 'use strict'; const common = require('../common'); const assert = require('assert');