Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: fix misleading error when import empty package.json #49728

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Sep 20, 2023

Fixes: #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

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Sep 20, 2023
@himself65 himself65 changed the title fix: misleading when import empty package.json fix(esm): misleading when import empty package.json Sep 20, 2023
@himself65 himself65 changed the title fix(esm): misleading when import empty package.json esm: misleading when import empty package.json Sep 20, 2023
@GeoffreyBooth
Copy link
Member

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.

@himself65
Copy link
Member Author

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 question is how to determine if a package.json is correct? Do we have such schema

@himself65
Copy link
Member Author

Updated

@himself65 himself65 force-pushed the himself65/fix-import branch 2 times, most recently from 4ee33aa to eb6d5cb Compare September 20, 2023 03:49
@himself65 himself65 changed the title esm: misleading when import empty package.json esm: fix misleading error when import empty package.json Sep 20, 2023
@himself65 himself65 added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 20, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 20, 2023
@nodejs-github-bot
Copy link
Collaborator

src/node_file.cc Outdated Show resolved Hide resolved
src/node_file.cc Outdated Show resolved Hide resolved
@avivkeller
Copy link
Member

@himself65 are you still interested in continueing this? There are outstanding comments, and failing tests.

@avivkeller avivkeller closed this Sep 14, 2024
@avivkeller avivkeller reopened this Sep 14, 2024
@avivkeller
Copy link
Member

Oops! Sorry... closed the wrong PR tab 😅

@himself65
Copy link
Member Author

@himself65 are you still interested in continueing this? There are outstanding comments, and failing tests.

Let me fix this

@himself65
Copy link
Member Author

working on it

@himself65
Copy link
Member Author

fixed!

@himself65
Copy link
Member Author

idk why format-cpp action will delete half of the file. any idea? @redyetidev

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.52%. Comparing base (72537f5) to head (011628e).
Report is 1 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% <ø> (ø)

... and 34 files with indirect coverage changes

@avivkeller
Copy link
Member

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

@aduh95
Copy link
Contributor

aduh95 commented Sep 18, 2024

There are some relevant test failures, PTAL

@himself65 himself65 requested a review from aduh95 September 19, 2024 04:28
Comment on lines 152 to 153
() => legacyMainResolve(packageJsonUrl, { main: './index.node' }, packageJsonUrl),
{ message: /index\.node/, code: 'ERR_MODULE_NOT_FOUND' },
{ message: /No package entry point defined for package/, code: 'ERR_MODULE_NOT_FOUND' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, there is an entry point defined, './index.node', but the resolution still fails because the file doesn't exist. This change would likely be confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah make sense, so I'm gonna check wheher user request a file or a module then give a differnt error

@himself65
Copy link
Member Author

I might pick this issue again because I see this error message and confusing me for hours😅

@himself65 himself65 force-pushed the himself65/fix-import branch from ce27df1 to d0b5261 Compare January 6, 2025 16:58
@himself65 himself65 force-pushed the himself65/fix-import branch from c23e1ea to 011628e Compare January 6, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

misleading error: Cannot find package '.../package.json', when package.json exists
6 participants