question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature request: support conditional exports (package.json `exports` field)

See original GitHub issue

Love the style support, but would really helpful for conditional exports to also be legible to postcss-import:

{
  ...,
  "exports": {
    ".": "./dist/index.js",
    "./*": "./dist/lib/*/index.js",
    "./styles": "./dist/styles/index.css",
    "./styles/*": "./dist/styles/*/index.css",
    "./package.json": "./package.json"
  },
  ...,
}

The main reason I suggest this is because I cannot specify an @import "my-package/styles" statement in a way that is supported by both esbuild (supports standardized package.json exports, but not nonstandard style) and postcss-import (where situation is reversed). my-package/styles is the only thing that works for esbuild, but my-package is the only thing that works for postcss-import.

I would recommend following the Node doctrine of “if exports exists, it overrides anything else” (i.e. style field). Also thank you for maintaining this project, it is a core part of modern development workflows IMO, only reason I suggest the enhancement.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Apr 12, 2022

The module we use for resolution doesn’t support exports yet; so that’s a technical blocker: https://github.com/browserify/resolve/issues/222.

Presumably, we’d want to support some kind of style-specific conditional export as well, so you could export both JS and CSS at ., similiar to how using both main & style works today. Does esbuild have anything like this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support "exports" field of package.json : WEB-40509 - YouTrack
If there are several conditional exports / imports, we merge all of them while resolving the import/require. The behavior is not equal to...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Conditional exports can be used within "exports" to define different package entry points per environment, including whether the package is referenced via ...
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
Node.JS (New) Package.json Exports Field | by Thomas Juster
Flavors like EcmaScript Module import … from '…' vs. CommonJS const … = require(…) How to use it. Consider the following architecture: my- ......
Read more >
How can I use "exports" in package.json today for nested ...
2021), the exports field in package.json was not supported by the ... separate feature which is specific to typescript only (read more about ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found