From 68498665fc512a77e96155b53da2faa094adebdb Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 26 Sep 2019 23:21:52 -0400 Subject: [PATCH 1/2] module: move cjs type check behind flag --- lib/internal/modules/cjs/loader.js | 2 +- test/es-module/test-esm-type-flag-errors.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 8ef01b4499a048..a5c6b268cc4ed9 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -953,7 +953,7 @@ Module.prototype._compile = function(content, filename) { // Native extension for .js Module._extensions['.js'] = function(module, filename) { - if (filename.endsWith('.js')) { + if (filename.endsWith('.js') && experimentalModules) { 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'); From 36cb1d11121a4553f6e13e222b65b6ab30baa7f1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 27 Sep 2019 11:29:38 -0400 Subject: [PATCH 2/2] switch flag logical order --- lib/internal/modules/cjs/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index a5c6b268cc4ed9..341163ef8c4d22 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -953,7 +953,7 @@ Module.prototype._compile = function(content, filename) { // Native extension for .js Module._extensions['.js'] = function(module, filename) { - if (filename.endsWith('.js') && experimentalModules) { + if (experimentalModules && filename.endsWith('.js')) { const pkg = readPackageScope(filename); if (pkg && pkg.type === 'module') { throw new ERR_REQUIRE_ESM(filename);