-
Notifications
You must be signed in to change notification settings - Fork 326
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
Importing a .stylex.ts does not work with tsconfig paths settings #40
Comments
If this support is not deliberately excluded, I would like to work on a PR to add this feature. @necolas |
The StyleX Babel plugin relies on the @rayan1810 Happy for accept your contribution to solve this problem! Please start by describing an outline of how you would solve it. Here's the relevant code:
|
I just did a POC, so if I check if it's a NextJS application and If it has aliases added in |
@rayan1810 This solution feels too specific to Next and TS. Perhaps there is a way to pass in an alias configuration to the Babel plugin itself? Then, the Next.js plugin can read the aliases and inject them into the Babel plugin while using it. |
I agree @nmn, tested the flow with a POC and it works. Working on a PR for the same. |
@rayan1810 I've given this problem some thought: #111 |
This issue seems to even happen for relative imports For example you can use this repo to reproduce it. Any idea why this could be happening ? |
A quick update is that StyleX can now be configured to resolve aliases, although the configuration requires absolute paths. See the Next example in the repo for an example. @AbhiPartha Please don't post the same comment in multiple issues. I'll keep this one as it's on an open issue and delete the other one for now. |
I was able to make it work using @storybook/next in combination with stylex next plugin Although giving more info about the above issue, It says only if tsconfig paths are set and can leave devs thinking it works for relative imports, the error happens irrespective of setting tsconfig alias or not. Error: |
@AbhiPartha yes. this is a known issue. The StyleX babel plugin can be configured to understand aliases. We don't automatically discover and read aliases defined in a |
Any clues on how we could do it for a nx monorepo project with a lib containing styleX ? Actually getting the same issue but there are no relative paths here. |
@jderboven Depends on the framework/bundler you're using. AFAIK, using Generally, you need to configure the build for your app to also compile the packages you're importing. These external packages may be from your mono-repo or Vite has a similar option AFAIK. (Although, you'd need to delete the Vite cache between builds for things to work consistently.)
Could you explain what this means? |
The problem
When importing a variable file like is listed in the docs, the build is only succeeding if the import path is a relative path (i.e. ../src/lib/theme/theme.stylex), but fails if the import path uses the tsconfig "paths" setting (i.e. @/lib/theme/theme.stylex when tsconfig paths is
{ '@/*' : '.src/*'} )
.With non-relative paths, it gives the
Only static values are allowed inside of a stylex.create() call
error message.How to reproduce
Steps to reproduce:
paths: { '@/*' : '.src/*'}
in the tsconfig.json file./src/lib/
that defines a color usingexport const colors = stylex.defineVars({test: '#000000'})
import { colors } from @/lib/theme.stylex
and usecolors.test
in astylex.create
call.Expected behavior
I would expect this to allow
colors
to be used instylex.create
as specified in the docs.Environment (include versions). Did this work in previous versions?
The text was updated successfully, but these errors were encountered: