Skip to content

Commit 77abfd1

Browse files
committed
esm: fix misleading error when import empty package.json
1 parent 6dfa3e4 commit 77abfd1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/node_file.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,8 +3439,9 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
34393439
}
34403440

34413441
THROW_ERR_MODULE_NOT_FOUND(isolate,
3442-
"Cannot find package '%s' imported from %s",
3443-
package_initial_file,
3442+
"No package entry point defined for package"
3443+
" %s imported from %s",
3444+
*utf8_package_json_url,
34443445
*module_base);
34453446
}
34463447

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const { spawnPromisified } = require('../common');
4+
const fixtures = require('../common/fixtures.js');
5+
const assert = require('node:assert');
6+
const { execPath } = require('node:process');
7+
const { describe, it } = require('node:test');
8+
9+
describe('Import empty module', { concurrency: true }, () => {
10+
it(async () => {
11+
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
12+
'--no-warnings',
13+
'--eval',
14+
'import("empty")',
15+
], {
16+
cwd: fixtures.path(),
17+
});
18+
assert.match(stderr, /No package entry point defined for package/);
19+
assert.strictEqual(stdout, '');
20+
assert.strictEqual(code, 1);
21+
assert.strictEqual(signal, null);
22+
});
23+
});

test/fixtures/node_modules/empty/package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)