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 2 commits 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
@RedYetiDev
Copy link
Member

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

@RedYetiDev RedYetiDev closed this Sep 14, 2024
@RedYetiDev RedYetiDev reopened this Sep 14, 2024
@RedYetiDev
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.04%. Comparing base (6dfa3e4) to head (ce27df1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #49728      +/-   ##
==========================================
+ Coverage   88.03%   88.04%   +0.01%     
==========================================
  Files         652      652              
  Lines      183765   183764       -1     
  Branches    35858    35856       -2     
==========================================
+ Hits       161771   161791      +20     
+ Misses      15239    15227      -12     
+ Partials     6755     6746       -9     
Files with missing lines Coverage Δ
src/node_file.cc 77.06% <100.00%> (+<0.01%) ⬆️

... and 26 files with indirect coverage changes

@RedYetiDev
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

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

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