Skip to content

Commit fec4a5d

Browse files
committed
module: ignore package.json/ directories
Fixes: nodejs#8307
1 parent 1b0d979 commit fec4a5d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lib/module.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ function readPackage(requestPath) {
123123
return entry;
124124

125125
const jsonPath = path.resolve(requestPath, 'package.json');
126+
const rc = stat(jsonPath);
127+
if (rc !== 0) {
128+
return false;
129+
}
126130
const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath));
127131

128132
if (json === undefined) {

test/fixtures/module-package-json-directory/package.json/index.js

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const fixtures = require('../common/fixtures');
5+
6+
try {
7+
require(fixtures.path('module-package-json-directory'));
8+
process.exit(1);
9+
} catch (err) {
10+
assert.ok(
11+
/Cannot find module/.test(err.message),
12+
`require() should ignore package.json/ directories: ${err.message}`);
13+
}

0 commit comments

Comments
 (0)