node icon indicating copy to clipboard operation
node copied to clipboard

esm: fix misleading error when import empty package.json

Open himself65 opened this issue 2 years ago • 15 comments

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

himself65 avatar Sep 20 '23 01:09 himself65

Review requested:

  • [ ] @nodejs/loaders

nodejs-github-bot avatar Sep 20 '23 01:09 nodejs-github-bot

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.

GeoffreyBooth avatar Sep 20 '23 02:09 GeoffreyBooth

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 avatar Sep 20 '23 02:09 himself65

Updated

himself65 avatar Sep 20 '23 03:09 himself65

CI: https://ci.nodejs.org/job/node-test-pull-request/54075/

nodejs-github-bot avatar Sep 20 '23 03:09 nodejs-github-bot

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

avivkeller avatar Sep 14 '24 22:09 avivkeller

Oops! Sorry... closed the wrong PR tab :sweat_smile:

avivkeller avatar Sep 14 '24 22:09 avivkeller

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

Let me fix this

himself65 avatar Sep 14 '24 22:09 himself65

working on it

himself65 avatar Sep 15 '24 00:09 himself65

fixed!

himself65 avatar Sep 15 '24 01:09 himself65

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

himself65 avatar Sep 15 '24 02:09 himself65

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% <ø> (ø)

... and 34 files with indirect coverage changes

: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.

codecov[bot] avatar Sep 15 '24 03:09 codecov[bot]

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

avivkeller avatar Sep 18 '24 21:09 avivkeller

There are some relevant test failures, PTAL

aduh95 avatar Sep 18 '24 23:09 aduh95

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

himself65 avatar Dec 04 '24 03:12 himself65

Closing as too outdated

himself65 avatar Jul 25 '25 10:07 himself65