Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c23e1ea

Browse files
committedJan 6, 2025·
fixup! esm: fix misleading error when import empty package.json
1 parent d0b5261 commit c23e1ea

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed
 

‎src/node_file.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -3493,9 +3493,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
34933493
}
34943494

34953495
THROW_ERR_MODULE_NOT_FOUND(isolate,
3496-
"No package entry point defined for package"
3497-
" %s imported from %s",
3498-
*utf8_package_json_url,
3496+
"Entry point '%s' resolved from '%s' incorrectly",
3497+
package_initial_file,
34993498
*module_base);
35003499
}
35013500

‎test/es-module/test-cjs-legacyMainResolve.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ describe('legacyMainResolve', () => {
129129
);
130130
assert.throws(
131131
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
132-
{ message: /No package entry point defined for package/, code: 'ERR_MODULE_NOT_FOUND' },
132+
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
133133
);
134134
});
135135

136136
it('should not crash when cannot resolve to a file that contains special chars', () => {
137137
const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json');
138138
assert.throws(
139139
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
140-
{ message: /No package entry point defined for package/, code: 'ERR_MODULE_NOT_FOUND' },
140+
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
141141
);
142142
});
143143

@@ -150,7 +150,7 @@ describe('legacyMainResolve', () => {
150150
);
151151
assert.throws(
152152
() => legacyMainResolve(packageJsonUrl, { main: './index.node' }, packageJsonUrl),
153-
{ message: /No package entry point defined for package/, code: 'ERR_MODULE_NOT_FOUND' },
153+
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
154154
);
155155
});
156156

‎test/es-module/test-import-empty.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Import empty module', { concurrency: true }, () => {
1515
], {
1616
cwd: fixtures.path(),
1717
});
18-
assert.match(stderr, /No package entry point defined for package/);
18+
assert.match(stderr, /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/);
1919
assert.strictEqual(stdout, '');
2020
assert.strictEqual(code, 1);
2121
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)
Please sign in to comment.