-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Esbuild and nodejs module resolution #4144
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
Comments
I don't think there's a good reason. That just sounds like a bug with esbuild. Looking at node's algorithm reference, the relevant part might be here:
I'm guessing the specification meant to say something like Thanks for the impressive name collision test case. This looks like a bug with esbuild. In the meantime, the library author should be able to work around it by avoiding the name collision. |
Thank you for your response @evanw. While debugging I was also reading the definition of node module resolution and I thought that esbuild was following the algorithm successfully but I couldn't figure out why nodejs was not failing in that case. Now that I read your explanation I'm supposing that's the issue. As well I checked the trailingSlash condition and our case(the relative path '..') meets that condition. |
I'm using esbuild to build a typescript project. I'm using a dependency in my typescript project that was coded with typescript however was transpiled to js and published like that, the structure of that dependency look like this from node_modules:
In package/index.js the dependency is exporting everything from utils and errors folders. Acting like a module file.
Also there is a something = require("..") in the utils file of the utils folder(package/utils/utils.js). I'm expecting that esbuild resolve the index.js in the parent folder. However is resolving the package.json. When I look at the esbuild verbose logs, I found this:
After a deep research I understood that node module resolution resolves the relative path ".." like that. But why while developing this dependency(mydependency) doing the import in the typescript file(utils.ts) I don't get this error. Why in typescript do not resolve to package.json? Also why if I run a testing.js file with nodejs(20.9.0) from mydependency folder that call a method in utils.js the require doesn't resolve to package.json an resolves correctly to the index.js in the parent directory (mydependency/package/index.js). But if I bundle this testing file with esbuild it resolves to package.json.
The text was updated successfully, but these errors were encountered: