-
Notifications
You must be signed in to change notification settings - Fork 75
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
Incorrect resolution for nested node_modules
due to usage of basedir
in NodeResolvePlugin
#233
Comments
3 tasks
I am unable to reproduce the issue raised in #66 / #68 for these combination of versions:
I have thus raised #234 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mdx-bundler
version: 10.0.3node
version: 18.8.0, 18.14.1, 20.12.1npm
version: 8.18.0, 9.5.0, 10.5.0esbuild
version: 0.19.12, 0.23.1@esbuild-plugins/node-resolve
version: 0.2.2Relevant code or config
//
c:/project/index-c.mdx
I have identified that usage of
basedir
in NodeResolvePlugin causes the incorrect module resolution to occur for nestednode_modules
.mdx-bundler/src/index.js
Lines 147 to 150 in 616c5b0
https://github.com/kentcdodds/mdx-bundler/pull/68/files#diff-bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556R149
What you did:
Attempt to bundle a component using package (package-a) with 2 different versions, imagine the
node_modules
structure like this* exact version doesn't matter here, only the folder structure matter
index-b
importspackage-b
importspackage-a
package-a
should resolve tonode_modules/package-a/a.js
index-c
importspackage-c
importspackage-a
package-a
should resolve tonode_modules/package-c/node_modules/package-a/a.js
What happened:
The incorrect module is resolved.
mdx-bundler
always resolve module at${process.cwd()}/node_modules
, breaking NodeJS's / ESBuild node module resolution logic.index-b
importspackage-b
importspackage-a
package-a
resolved tonode_modules/package-a/a.js
index-c
importspackage-c
importspackage-a
package-a
resolved tonode_modules/package-a/a.js
<-- ❌ incorrect resolutionReference:
esbuild
- implements NodeJS module resolution@esbuild-plugins/node-resolve
- by default follow NodeJS module resolution ifbasedir
is not passed, and start looking fornode_modules
from the caller's moduleReproduction repository:
A basic reproduce repo is created to demonstrate this point using only
esbuild
and@esbuild-plugins/node-resolve
https://github.com/amoshydra/repro-kentcdodds-mdx-bundler/tree/repro-issue-233
Test setup
build.mjs contains 3 setup:
esbuild
without pluginesbuild
with@esbuild-plugins/node-resolve
using default optionesbuild
with@esbuild-plugins/node-resolve
passing project's working directory as basedirObservation
dist
folder contain the output for each buildProblem description:
mdx-bundler
should follow NodeJS module resolution, but it does not.Consequently, as we migrate our bundler from
webpack/docz
tomdx-bundler
, we observe many of the packages failed to run due to incorrect module resolutionSuggested solution:
For the scope of my project, the following workarounds works for me:
removing@esbuild-plugins/node-resolve
, let esbuild perform the resolution(mdx-bundler cannot load
md
file if plugin is removed.mdx
loads fine)@esbuild-plugins/node-resolve
without thebasedir
optionEarlier, I wanted to suggest removing
basedir
.However
basedir
appear to be added intentionally in #68. I have yet to look into what problem #68 is trying to solveThe text was updated successfully, but these errors were encountered: