diff --git a/src/node_file.cc b/src/node_file.cc index f569eea1a7f9b8..731245816f70e1 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3439,8 +3439,9 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { } THROW_ERR_MODULE_NOT_FOUND(isolate, - "Cannot find package '%s' imported from %s", - package_initial_file, + "No package entry point defined for package" + " %s imported from %s", + *utf8_package_json_url, *module_base); } diff --git a/test/es-module/test-import-empty.js b/test/es-module/test-import-empty.js new file mode 100644 index 00000000000000..c073a35777860b --- /dev/null +++ b/test/es-module/test-import-empty.js @@ -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.match(stderr, /No package entry point defined for package/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); + }); +}); diff --git a/test/fixtures/node_modules/empty/package.json b/test/fixtures/node_modules/empty/package.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/test/fixtures/node_modules/empty/package.json @@ -0,0 +1 @@ +{}