Replies: 1 comment
-
|
One more thing I wanted to call out, separate from the webpack resolution question above. Early on, there were Next.js examples that integrated Open Props ( You can still see traces of that in the repo history. For example, PR #781 updated the Next.js example's PostCSS config to include I completely understand why those examples were trimmed over time — you don't want third-party libraries cluttering the core StyleX docs. But the use case didn't go away. Shipping an uncompiled design system and compiling it in the consuming app is, I think, a common pattern (we're doing it with our own packages; others will do the same). The problem is that the current Next.js installation guide reads like it covers every Next + StyleX app. In practice it documents app-local StyleX only:
That's a different integration than the guide describes, especially with Next.js 16 defaulting to Turbopack and excluding It would help a lot if the docs had a dedicated section for this pattern — even a short "Consuming an uncompiled StyleX library" page that points to the extra PostCSS + bundler config, calls out the tradeoffs (double compile, transitive dependency resolution, etc.), and maybe links to this thread. Happy to contribute wording or a doc PR if that's useful. Thanks again for engaging on this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Setup
We have a Next.js app that consumes a shared component library and a design tokens package. Both ship uncompiled StyleX — the packages are built with tsup (TypeScript to JavaScript), but
stylex.create()/stylex.props()calls are left in the output for the consumer to compile at build time.To handle this, we run
babel-loader+@stylexjs/babel-pluginon those packages insidenode_modulesvia a custom webpack rule, and use@stylexjs/postcss-pluginfor CSS generation:This works for StyleX compilation. The problem is what it does to webpack's module resolution.
The problem
When the webpack babel rule targets our component library inside
node_modules, webpack treats the entire package as source code and follows its full import graph — including into transitive dependencies that have nothing to do with StyleX.Our component library includes chart components that import from
@highcharts/react, which internally importshighcharts/esm/highcharts.src.js. That file is a webpack-prebundled artifact (it contains its own embedded__webpack_require__runtime). When our app's webpack follows the import chain into that file and tries to re-process it, the two webpack runtimes conflict and the app crashes:We only need webpack to run the StyleX babel plugin on our library's files. We don't need it to chase and re-process every transitive dependency the library imports. But the webpack rule's
includepattern controls which files the loader runs on — it doesn't prevent webpack from resolving and processing the imports found in those files.Our workaround
We added a webpack alias to redirect the specific problematic import:
This redirects from the prebundled ESM artifact to the standard source file (same package, same version, same API — just a different module format wrapper). It works, but it's a per-dependency workaround. If another transitive dependency has a similar packaging issue, we'd need another alias.
The Highcharts packaging issue is tracked upstream at highcharts/highcharts#24243.
The question
Is there a recommended way to run the StyleX babel plugin on packages inside
node_moduleswithout causing webpack to deeply resolve their entire transitive import graph?To be specific about what we need:
@highcharts/react,highcharts, or anything else the library depends on that doesn't contain StyleXIs there a configuration pattern, a webpack feature, or a different integration approach that would give us this kind of scoping? Or is the expectation that consumers running the StyleX babel plugin on
node_modulespackages will inherently cause webpack to follow the full import graph, and workarounds like ours are the way to handle any conflicts that arise?Beta Was this translation helpful? Give feedback.
All reactions