esm: fix misleading error when import empty package.json
Fixes: https://github.com/nodejs/node/issues/49674
➜ node /Users/himself65/Code/node/out/Debug/node -e 'import("whatever")'
node:internal/process/promises:394
triggerUncaughtException(err, true /* fromPromise */);
^
Error: No package entry point defined for package 'file:///Users/himself65/Code/xxx/node_modules/whatever/package.json' imported from xxx/src/index.ts
at legacyMainResolve (node:internal/modules/esm/resolve:207:26)
at packageResolve (node:internal/modules/esm/resolve:826:14)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at resolve (file:///Users/himself65/Applications/WebStorm.app/Contents/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/esm/index.mjs?1726363031016:2:3893)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
at handleMessage (node:internal/modules/esm/worker:199:24)
at Immediate.checkForMessages (node:internal/modules/esm/worker:141:28) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v23.0.0-pre
Process finished with exit code 1
Review requested:
- [ ] @nodejs/loaders
The problem isn't really that main isn't a string; it's that the package.json is invalid. We also discourage the use of main nowadays since exports replaces it.
The problem isn't really that
mainisn't a string; it's that thepackage.jsonis invalid. We also discourage the use ofmainnowadays sinceexportsreplaces it.
The question is how to determine if a package.json is correct? Do we have such schema
Updated
CI: https://ci.nodejs.org/job/node-test-pull-request/54075/
@himself65 are you still interested in continueing this? There are outstanding comments, and failing tests.
Oops! Sorry... closed the wrong PR tab :sweat_smile:
@himself65 are you still interested in continueing this? There are outstanding comments, and failing tests.
Let me fix this
working on it
fixed!
idk why format-cpp action will delete half of the file. any idea? @RedYetiDev
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 88.52%. Comparing base (
72537f5) to head (011628e). Report is 1467 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #49728 +/- ##
==========================================
- Coverage 88.52% 88.52% -0.01%
==========================================
Files 660 660
Lines 190900 190900
Branches 36631 36638 +7
==========================================
- Hits 168998 168997 -1
+ Misses 15097 15086 -11
- Partials 6805 6817 +12
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/node_file.cc | 77.37% <ø> (ø) |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
idk why format-cpp action will delete half of the file. any idea? @RedYetiDev
Rebase with the latest changes to main to resolve the issue. #54994
There are some relevant test failures, PTAL
I might pick this issue again because I see this error message and confusing me for hours😅
Closing as too outdated