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

node modules resolver should return a fallback path for package not located by require.resolve #919

Closed
1 of 5 tasks
thescientist13 opened this issue Mar 25, 2022 · 1 comment · Fixed by #920 or #912
Closed
1 of 5 tasks
Assignees
Labels
alpha.3 CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.25.0
Milestone

Comments

@thescientist13
Copy link
Member

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

As part of #917 , noticed that inadvertently when puppeteer was added to dependencies, all of a sudden certain packages would fail the getNodeModulesLocationForPackage utility function look up, and error out in the terminal.

{ locations: null }
Unable to look up punycode using NodeJS require.resolve.
Falling back to process.cwd()
=============

  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
      at validateString (internal/validators.js:124:11)
      at Object.join (path.js:1110:7)
      at walkPackageJson (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/walker-package-ranger.js:202:44)
      at async walkPackageJson (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/walker-package-ranger.js:209:11)
      at async walkPackageJson (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/walker-package-ranger.js:209:11)
      at async walkPackageJson (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/walker-package-ranger.js:209:11)
      at async walkPackageJson (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/walker-package-ranger.js:209:11)
      at async file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/plugins/resource/plugin-node-modules.js:103:13

What's interesting is that there is no change in dependecies before / after moving puppeteer into dependencies?

# before
yarn why punycode
yarn why v1.22.5
[1/4] 🤔  Why do we have the module "punycode"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Reasons this module exists
   - "_project_#whatwg-url#tr46" depends on it
   - Hoisted from "_project_#whatwg-url#tr46#punycode"
   - Hoisted from "_project_#ajv#uri-js#punycode"
   - Hoisted from "_project_#jsdom#tough-cookie#punycode"
info Disk size without dependencies: "48KB"
info Disk size with unique dependencies: "48KB"
info Disk size with transitive dependencies: "48KB"
info Number of shared dependencies: 0
✨  Done in 0.88s.

# after
yarn why punycode
yarn why v1.22.5
[1/4] 🤔  Why do we have the module "punycode"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Reasons this module exists
   - "_project_#whatwg-url#tr46" depends on it
   - Hoisted from "_project_#whatwg-url#tr46#punycode"
   - Hoisted from "_project_#ajv#uri-js#punycode"
   - Hoisted from "_project_#jsdom#tough-cookie#punycode"
info Disk size without dependencies: "48KB"
info Disk size with unique dependencies: "48KB"
info Disk size with transitive dependencies: "48KB"
info Number of shared dependencies: 0
✨  Done in 0.88s.

Details

Not sure why locations is null, but I suppose there's no reason we couldn't at least try and do something, like fallback to process.cwd() I suppose

if (!nodeModulesUrl) {
  console.debug(`Unable to look up ${packageName} using NodeJS require.resolve.`);
  // we could / should at least try to provide a fallback here?
}

Maybe this issue is relevant? - ajv-validator/ajv#1381

Note: somewhat related, but I think the import.meta.resolve logic is actually broken... 🙈 😬

@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) CLI labels Mar 25, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Mar 25, 2022
@thescientist13 thescientist13 self-assigned this Mar 25, 2022
@thescientist13 thescientist13 changed the title node modules resolver should return best guess location for a package node modules resolver should return a fallback oath for package not located by require.resolve Mar 25, 2022
@thescientist13 thescientist13 changed the title node modules resolver should return a fallback oath for package not located by require.resolve node modules resolver should return a fallback path for package not located by require.resolve Mar 25, 2022
@thescientist13
Copy link
Member Author

Another related thread possibly - nodejs/node#29549

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.3 CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.25.0
Projects
None yet
1 participant