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 f23c1e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3431,6 +3431,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
return;
}

// todo(himself65): `"Cannot find entry file for module " + module_path + " in " + module_base;`

THROW_ERR_MODULE_NOT_FOUND(isolate,
"Cannot find package '%s' imported from %s",
package_initial_file,
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, /ERR_INVALID_MODULE/);
});
});
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 f23c1e4

Please sign in to comment.