Open krtcom opened 1 month ago
It seems to only happen with loader: { '.js': 'ts' }
. I'm not sure what insane project you're facing where people write TypeScript in .js files. However, you can check what's going on for all resolver errors with logLevel: 'verbose'
.
Look at the difference between whether to set '.js': 'ts'
:
...
Attempting to load "path/to/project/node_modules/core-js/stable" as a file
Checking for file "stable"
+ Checking for file "stable.js"
+ Checking for file "stable.tsx"
+ Checking for file "stable.ts"
+ Checking for file "stable.jsx"
+ Checking for file "stable.css"
+ Checking for file "stable.json"
Failed to find file "stable"
...
It seems in that case esbuild won't try to resolve arbitrary file extensions (including index[ext]
).
I have a very specific problem regarding ts and tsx loader and imports from node_modules that do not have extension specified. Steps or files to reproduce:
package.json:
app.jsx:
build.mjs:
When I run
node build.mjs
I get this error:Could not resolve "core-js/stable"
. Seems like a problem with resolving fileindex.js
incore-js/stable
folder. If I specify this file directly it works, but then it fails to resolve other imports form this file.Likewise, if I import a file from
node_modules
without extension - in my case it wasimport 'regenerator-runtime/runtime'
- the build fails withCould not resolve "regenerator-runtime/runtime"
but if I provide full file name with extensionimport 'regenerator-runtime/runtime.js'
, it works.By gradual elimination and trial-error method I discovered, that it may have something to do with
tsx
andts
loader. If I comment out either'.jsx': 'tsx'
or'.js': 'ts'
line from build.mjs the resolution and build works. However, I need tsx transformation, because of experimental decorators that we are using through all of our project.This also happes when I import some library which has a file without extension in its
"main"
field inpackage.json
(eg."main": "es/index"
)Interestingly, this setup was working in esbuild 0.19.* and stopped working in 0.20 (tested also all newer versions but without success). So I assume it may have something to do with 'Reorder implicit file extensions within node_modules' change in 0.20.0
I also tested multiple node versions 19, 20, 21, 22 all with the same results.
Please, can you confirm if this is a bug or just some incorrect setting, in which case please point me to the right direction.