Replies: 4 comments 5 replies
-
This should be working. This is likely a CLI bug. Please report back with what you find out. |
Beta Was this translation helpful? Give feedback.
-
Nope, doesn't appear to be the issue. Following a thread with the developer of the SWC plugin, but it appears to be independent of StyleX. Back to my CLI issue, I am still getting Some other info from error consoles ⨯ node_modules/@stylexjs/stylex/lib/es/stylex.mjs (174:1) @ errorForFn
⨯ Error: 'stylex.defineVars' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'
at __webpack_require__ (/Users/brian.mccarthy/Development/trashy/CLIDemo/.next/server/webpack-runtime.js:33:42)
at eval (./src/app/page.js:11:93)
at (rsc)/./src/app/page.js (/Users/brian.mccarthy/Development/trashy/CLIDemo/.next/server/app/page.js:173:1)
at Function.__webpack_require__ (/Users/brian.mccarthy/Development/trashy/CLIDemo/.next/server/webpack-runtime.js:33:42)
at async Promise.all (index 0)
digest: "4168016251"
172 | styleq.factory = createStyleq;
173 |
> 174 | const errorForFn = name => new Error(`'stylex.${name}' should never be called at runtime. It should be compiled away by '@stylexjs/babel-plugin'`);
| ^
175 | const errorForType = key => errorForFn(`types.${key}`);
176 | function props() {
177 | const options = this; I have set up a demo repo. https://github.com/BMCwebdev/CLIDemo I took a copy of your CLI demo: I install my token package, and tried using it in the My token repo: https://github.com/BMCwebdev/stylexAcmeNextTest/tree/main/packages/tokens I will send you cookies if you take a peek! Side question: I noticed that in your repo you have it set up somehow that I don't have to go through the whole rigamaroll to get watchman installed, which is great because my work computer (and moreso for my developers) is not so easy to install things like that (unsigned packages etc). Hopefully that is something I will be able to reproduce? @nmn Thank you again. I have come to love StyleX so much, and I have a large group of developers I am excited to onboard and get them to fall in love too. |
Beta Was this translation helpful? Give feedback.
-
Okay, getting close here! So I have the CLI working (and the SWC community plugin working) when I make a version of my token library with only 1 file. Something about my current setup breaks what StyleX must be expecting. For example, if I import something from the package published by this repository, which only has one token file, everything works But, if I import something from the package published by this repository, which has 2 token files, I will get the defineVars error. There must be something about my setup (with two files) that is incorrect, but I'm not sure what StyleX doesn't like about it, or what the correct method should be. But soooooo close now! |
Beta Was this translation helpful? Give feedback.
-
Hey @nmn and @Jta26 just wanted to give you both a ping on this one. I think I found something worth persuing. I have been trying to get the CLI to work for me for a while, and one wall I often hit is I will get an error saying that defineVars should be compiled away. This confused me because if I look in the compiled app folder, there are no calls for defineVars. What I did discover however, is that the import for my token library stays behind. And I suppose even though the usage of the token library is no longer in the file (because it has all been compiled away) the import alone perhaps is trying to pull in another copy of the un-compiled token library? Example of un-compiled and compiled file // un-compiled
'use client';
import * as stylex from '@stylexjs/stylex';
import { coreTokens as $ } from '@bonterratech/stitch-tokens/coreTokens.stylex';
export const styles = stylex.create({
banner: {
color: $['--s-color-red-500']
}
});
export default function Home() {
return (
<div {...stylex.props(styles.banner)}>hiagain</div>
);
} // compiled
'use client';
import "../../stylex_bundle.css";
import * as stylex from '@stylexjs/stylex';
import { coreTokens as $ } from '@bonterratech/stitch-tokens/coreTokens.stylex';
export const styles = {
banner: {
color: "x60dknu",
$$css: true
}
};
export default function Home() {
return <div {...{
className: "x60dknu"
}}>hiagain</div>;
} If I delete I don't think that is the only issue. That worked when I used a simplified version of my app. When I try to use the full app, even if I go through the compiled code and remove all of the instances of the above import I still get defineVars error. So there must be something else as well. But hopefully this is useful feedback for you. |
Beta Was this translation helpful? Give feedback.
-
I was having an issue link to discussion with the CLI where it would keep telling me that I had defineVars that should have been compiled. While playing with https://github.com/Dwlad90/nextjs-app-dir-stylex I was getting the same errors. I think I found something. I'll just make a quick post about it, and follow up later as it is bedtime.
The issue seems to stem from having tokens in a stylex.js file that reference earlier tokens.
FYI, I am following the OpenProps example from StyleX
if I remove the tokens from the bottom that reference earlier tokens, the above mentioned plugin will work. I am going to try with the CLI tomorrow.
Beta Was this translation helpful? Give feedback.
All reactions