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

fix: remove basedir in resolveOptions, allow original NodeJS resolve algorithm #234

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

Conversation

amoshydra
Copy link

@amoshydra amoshydra commented Sep 1, 2024

What:

Fix #233.
Allow NodeJS original node_module algorithm to be used by @esbuild-plugins/node-resolve / resolve.

Why:

#68 specified basedir to cwd which causes all node_modules resolution to start at cwd. This prevent nested node_modules to ever be resolved. See #233

Below illustrate the incorrect search paths when basedir is mapped to cwd

cwd:
- "/project"

import:
- "package-a"

caller:
- "/project/node_modules/package-c"

search_paths:
- "/project/node_modules/package-a"
- "/node_modules/package-a"

How:

By removing resolveOptions.basedir, it allow @esbuild-plugins/node-resolve / resolve to use the default NodeJS node_modules resolve algorithm where node_modules resolution starts from the directory of the caller module.

Below illustrate the correct search paths

cwd:
- "/project"

import:
- "package-a"

caller:
- "/project/node_modules/package-c"

search_paths:
- "/project/node_modules/package-c/node_modules/package-a"
- "/project/node_modules/package-a"
- "/node_modules/package-a"

Checklist:

@amoshydra amoshydra force-pushed the remove-basedir-in-resolve-options branch from 0d392e6 to dbe1b40 Compare September 1, 2024 09:07
@amoshydra amoshydra changed the title fix: remove basedir in rsolve options, allow original NodeJS resolve algorithm fix: remove basedir in resolveOptions, allow original NodeJS resolve algorithm Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect resolution for nested node_modules due to usage of basedir in NodeResolvePlugin
1 participant