Comments (3)
esbuild should read
exports:browser
instead ofexports:.
You are confusing two separate things. In this context, browser
is a condition whereas .
is a subpath. The subpath .
is necessary because you are importing the package itself (import "ulidx"
is treated like import "ulidx/."
with the way the algorithm works). I assume you want the subpath .
to be resolved using the browser
condition.
The node_modules/ulidx/package.json
looks like this:
{
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/node/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/node/index.cjs"
},
"node": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/node/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/node/index.cjs"
}
},
"browser": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/browser/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/browser/index.cjs"
}
},
"worker": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/browser/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/browser/index.cjs"
}
}
}
},
...
}
There is only one exported subpath (called "."
) so esbuild is correct for using it. The package provides five ways to resolve the subpath .
in order of priority depending on what conditions are currently active: import
, require
, node
, browser
, and worker
. However, since all path resolutions will either be an import
statement or a require
call, only the first two path resolutions will ever be used. None of the last three path resolutions (node
, browser
, and worker
) will ever be chosen because they all come after both import
and require
in priority order.
I'm closing this issue because esbuild seems to be working correctly here. The problem here is that the package definition is broken. It looks like the change that broke it is here: perry-mitchell/ulidx#41. I recommend working with the package author to fix their package. I'm not familiar with how the types
condition works, but it's possible their package could be made to work by reverting that change and then adding a default
condition that goes last and specifies the default behavior for when no other conditions match. Documentation about how conditions work can be found here: https://nodejs.org/api/packages.html#conditional-exports
from esbuild.
I recently just learnt how TypeScript resolves types, so I will put some additional info here.
First of all, in summary of what Evan said, the order of fields in "exports"
matters. The first matched condition will take effect (like import
> browser
in that case).
For TypeScript, the "types"
condition in "exports"
should always come first. However, in order to make that work, there're 2 other things need to ensure:
- The TypeScript version should be ≥ 4.7.
- The
"moduleResolution"
is set to"bundler"
or"nodenext"
. This is needed for TypeScript to pick up the "modern" resolution algorithm, i.e. respect the"exports"
field. Here's another article that convince you to do this.
from esbuild.
Thanks for info!
I see that someone already reported it in ulidx repository.
I hope it will get resolved soon. Until then I will use custom patch with patch-package
.
from esbuild.
Related Issues (20)
- Should fold let decl HOT 1
- Esbuild Won't Drop Unused Functions Created by Other Functions HOT 2
- Drop Unused Imports HOT 4
- enhance dead code elimination HOT 2
- Can not run private fields in the decorator
- Get a wrong build result when first element of typescript enum is not a Literal value HOT 2
- Target chrome53 does not cover Object.fromEntries HOT 2
- Provide support for AWS Inspector compatability HOT 3
- new Buffer() -> TypeError: Cannot read properties of null (reading '0') -> starting on node 20.15 HOT 2
- Why "for the web"? HOT 2
- How to get build progress? HOT 1
- About the Golang filepath fix on wasm HOT 2
- Yarn PnP activating when project has nodeLinker: node-modules HOT 2
- Child combinator (>) in :has sometimes vanishes when transpiling nested css
- Exclude JSON from sourcemaps
- Requestion: New release for update go 1.22.4 => 1.22.5 HOT 1
- feat: typescript project reference incremental build support HOT 1
- Inconsistent minify output caused by type import HOT 3
- ReferenceError in strict mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esbuild.