Skip to content

Commit

Permalink
esm: fix misleading error when import empty package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Sep 15, 2024
1 parent a65105e commit 1a50565
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3431,10 +3431,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
return;
}

THROW_ERR_MODULE_NOT_FOUND(isolate,
"Cannot find package '%s' imported from %s",
package_initial_file,
*module_base);
THROW_ERR_MODULE_NOT_FOUND(
isolate,
"No package entry point defined for package %s imported from %s",
*utf8_package_json_url,
*module_base);
}

void BindingData::MemoryInfo(MemoryTracker* tracker) const {
Expand Down
23 changes: 23 additions & 0 deletions test/es-module/test-import-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const { spawnPromisified } = require('../common');
const fixtures = require('../common/fixtures.js');
const assert = require('node:assert');
const { execPath } = require('node:process');
const { describe, it } = require('node:test');

describe('Import empty module', { concurrency: true }, () => {
it(async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--eval',
'import("empty")',
], {
cwd: fixtures.path(),
});
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
assert.strictEqual(stdout, '');
assert.match(stderr, /No package entry point defined for package/);
});
});
1 change: 1 addition & 0 deletions test/fixtures/node_modules/empty/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a50565

Please sign in to comment.