diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 11b14015cfb0fb..5949a5b8f01a15 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2350,12 +2350,15 @@ with no performance impact since Node.js 10. ### DEP0128: modules with an invalid `main` entry and an `index.js` file -Type: Documentation-only (supports [`--pending-deprecation`][]) +Type: Runtime Modules that have an invalid `main` entry (e.g., `./does-not-exist.js`) and also have an `index.js` file in the top level directory will resolve the diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 12eb3ebb3bb2ec..0619d64028dbd5 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -352,7 +352,7 @@ function tryPackage(requestPath, exts, isMain, originalPath) { err.requestPath = originalPath; // TODO(BridgeAR): Add the requireStack as well. throw err; - } else if (pendingDeprecation) { + } else { const jsonPath = path.resolve(requestPath, 'package.json'); process.emitWarning( `Invalid 'main' field in '${jsonPath}' of '${pkg}'. ` + diff --git a/test/parallel/test-module-loading-deprecated.js b/test/parallel/test-module-loading-deprecated.js index 3aa81eea6e906a..3b43284aec762d 100644 --- a/test/parallel/test-module-loading-deprecated.js +++ b/test/parallel/test-module-loading-deprecated.js @@ -1,5 +1,3 @@ -// Flags: --pending-deprecation - 'use strict'; const common = require('../common'); diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 2a5cb5edd07f57..6fb24f2f0210a9 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -29,8 +29,7 @@ const path = require('path'); const backslash = /\\/g; -if (!process.env.NODE_PENDING_DEPRECATION) - process.on('warning', common.mustNotCall()); +process.on('warning', common.mustCall()); console.error('load test-module-loading.js'); @@ -107,7 +106,16 @@ const d2 = require('../fixtures/b/d'); assert.strictEqual(require('../fixtures/packages/index').ok, 'ok'); assert.strictEqual(require('../fixtures/packages/main').ok, 'ok'); assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok'); + +common.expectWarning( + 'DeprecationWarning', + "Invalid 'main' field in '" + + require.resolve('../fixtures/packages/missing-main/package.json') + + "' of 'doesnotexist.js'. Please either fix that or report it to the" + + ' module author', + 'DEP0128'); assert.strictEqual(require('../fixtures/packages/missing-main').ok, 'ok'); + assert.throws( () => require('../fixtures/packages/missing-main-no-index'), {