Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a50565

Browse files
committedSep 15, 2024·
esm: fix misleading error when import empty package.json
1 parent a65105e commit 1a50565

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
 

‎src/node_file.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -3431,10 +3431,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
34313431
return;
34323432
}
34333433

3434-
THROW_ERR_MODULE_NOT_FOUND(isolate,
3435-
"Cannot find package '%s' imported from %s",
3436-
package_initial_file,
3437-
*module_base);
3434+
THROW_ERR_MODULE_NOT_FOUND(
3435+
isolate,
3436+
"No package entry point defined for package %s imported from %s",
3437+
*utf8_package_json_url,
3438+
*module_base);
34383439
}
34393440

34403441
void BindingData::MemoryInfo(MemoryTracker* tracker) const {

‎test/es-module/test-import-empty.js

+23
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.strictEqual(code, 1);
19+
assert.strictEqual(signal, null);
20+
assert.strictEqual(stdout, '');
21+
assert.match(stderr, /No package entry point defined for package/);
22+
});
23+
});

‎test/fixtures/node_modules/empty/package.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.