Skip to content

Commit 76a073b

Browse files
committed
module: runtime deprecate invalid package.json main entries
PR-URL: #37204 Fixes: #26588 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 80098e6 commit 76a073b

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2350,12 +2350,15 @@ with no performance impact since Node.js 10.
23502350
### DEP0128: modules with an invalid `main` entry and an `index.js` file
23512351
<!-- YAML
23522352
changes:
2353+
- version: REPLACEME
2354+
pr-url: https://github.com/nodejs/node/pull/37204
2355+
description: Runtime deprecation.
23532356
- version: v12.0.0
23542357
pr-url: https://github.com/nodejs/node/pull/26823
23552358
description: Documentation-only.
23562359
-->
23572360

2358-
Type: Documentation-only (supports [`--pending-deprecation`][])
2361+
Type: Runtime
23592362

23602363
Modules that have an invalid `main` entry (e.g., `./does-not-exist.js`) and
23612364
also have an `index.js` file in the top level directory will resolve the

lib/internal/modules/cjs/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function tryPackage(requestPath, exts, isMain, originalPath) {
352352
err.requestPath = originalPath;
353353
// TODO(BridgeAR): Add the requireStack as well.
354354
throw err;
355-
} else if (pendingDeprecation) {
355+
} else {
356356
const jsonPath = path.resolve(requestPath, 'package.json');
357357
process.emitWarning(
358358
`Invalid 'main' field in '${jsonPath}' of '${pkg}'. ` +

test/parallel/test-module-loading-deprecated.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Flags: --pending-deprecation
2-
31
'use strict';
42

53
const common = require('../common');

test/sequential/test-module-loading.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ const path = require('path');
2929

3030
const backslash = /\\/g;
3131

32-
if (!process.env.NODE_PENDING_DEPRECATION)
33-
process.on('warning', common.mustNotCall());
32+
process.on('warning', common.mustCall());
3433

3534
console.error('load test-module-loading.js');
3635

@@ -107,7 +106,16 @@ const d2 = require('../fixtures/b/d');
107106
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok');
108107
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok');
109108
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok');
109+
110+
common.expectWarning(
111+
'DeprecationWarning',
112+
"Invalid 'main' field in '" +
113+
require.resolve('../fixtures/packages/missing-main/package.json') +
114+
"' of 'doesnotexist.js'. Please either fix that or report it to the" +
115+
' module author',
116+
'DEP0128');
110117
assert.strictEqual(require('../fixtures/packages/missing-main').ok, 'ok');
118+
111119
assert.throws(
112120
() => require('../fixtures/packages/missing-main-no-index'),
113121
{

0 commit comments

Comments
 (0)