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 20, 2023
1 parent e9ff810 commit eb6d5cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3047,11 +3047,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
return;
}

std::string error_invalid_module_path =
"Cannot find entry file for module " + module_path + " in " + module_base;

env->isolate()->ThrowException(
ERR_MODULE_NOT_FOUND(env->isolate(),
"Cannot find package '%s' imported from %s",
module_path,
module_base));
ERR_INVALID_MODULE(env->isolate(), error_invalid_module_path.c_str()));
}

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, /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 eb6d5cb

Please sign in to comment.