Skip to content

Commit eb6d5cb

Browse files
committed
esm: fix misleading error when import empty package.json
1 parent e9ff810 commit eb6d5cb

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/node_file.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,11 +3047,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
30473047
return;
30483048
}
30493049

3050+
std::string error_invalid_module_path =
3051+
"Cannot find entry file for module " + module_path + " in " + module_base;
3052+
30503053
env->isolate()->ThrowException(
3051-
ERR_MODULE_NOT_FOUND(env->isolate(),
3052-
"Cannot find package '%s' imported from %s",
3053-
module_path,
3054-
module_base));
3054+
ERR_INVALID_MODULE(env->isolate(), error_invalid_module_path.c_str()));
30553055
}
30563056

30573057
void BindingData::MemoryInfo(MemoryTracker* tracker) const {
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.strictEqual(code, 1);
19+
assert.strictEqual(signal, null);
20+
assert.strictEqual(stdout, '');
21+
assert.match(stderr, /ERR_INVALID_MODULE/);
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)