Title; Compilation Error, with Stylex. Values allowed inside the stylex.create() function
Environment;
Operating System; Ubuntu 22.04 (WSL)
Next.js Version; 14.0.2
Stylex Version; 0.3.0
Webpack Version; (Included with Next.js)
Description;
I encountered an issue while trying to compile a Next.js project that uses Stylex for styling. The build process. Displays an error message stating that only static values can be used inside the stylex.create() function call. This problem occurs even though I followed the documentation, which instructs to define variables using stylex.defineVars() and use them within stylex.create().
like so:
import * as stylex from "@stylexjs/stylex";
export const staticColors = stylex.defineVars({
colorsBaseBlack: "#000000",
colorsBaseWhite: "#ffffff",
colorsBlue100: "#d1e9ff",
colorsBlue200: "#b2ddff",
colorsBlue25: "#f5faff",
// ...
})
and used it like so:
import { staticColors } from "@/themes/static-colors.stylex";
import * as stylex from "@stylexjs/stylex";
export const styles = stylex.create({
container: {
display: "flex",
padding: "0 24px",
alignItems: "flex-start",
gap: 8,
alignSelf: "stretch",
},
title: {
color: staticColors.colorsGray900,
fontSize: "1.25rem",
fontStyle: "normal",
fontWeight: 600,
lineHeight: 1.5,
},
});
Steps to Reproduce;
- Define CSS variables by utilizing
stylex.defineVars() in a file called tokens.stylex.ts.
- Import these variables and incorporate them within a
stylex.create() call in a component.
- Execute the
build command to compile the project.
Expected Result;
The project should successfully compile, with Stylex processing the CSS variable definitions and applying them as intended.
Actual Result;
The build process encounters an error that states;
Failed to compile
./src/components/atoms/slideout menu header/style.stylex.ts
Error;
.../src/components/atoms/slideout menu header/style.stylex.ts; Only static values are allowed inside of a stylex.create() call.
, at transformFile.next (<anonymous>)
at run.next (<anonymous>)
at transform.next (<anonymous>)
This error indicates that there might be dynamic values being passed to stylex.create() which is not supported.
Additional Information;
The Next.js configuration has been customized to utilize the @stylexjs/webpack plugin for StyleX.
Due to the issue, with Google Fonts and the Next.js StyleX plugin it was decided to use the Webpack plugin
Note: It is observed that the compilation works when stylex.create() is used with a function that returns the style object, as shown below:
export const styles = stylex.create({
container: () => ({
backgroundColor: staticColors.colorsBaseWhite,
}),
});
However, this approach is contrary to the examples provided in the Stylex documentation where stylex.create() is directly given an object. The expected usage, as per the documentation, which is currently not working, is:
import * as stylex from '@stylexjs/stylex';
import { staticColors } from '../path/to/tokens.stylex';
const styles = stylex.create({
container: {
backgroundColor: staticColors.colorsBaseWhite,
},
});
This inconsistency between the documentation and the actual working solution suggests a potential issue with the library's handling of variable definitions within stylex.create() calls.
Thanks for reviewing the issue, we are looking forward to use this in our app,
Samplead Team
Title; Compilation Error, with Stylex. Values allowed inside the stylex.create() function
Environment;
Operating System; Ubuntu 22.04 (WSL)
Next.js Version; 14.0.2
Stylex Version; 0.3.0
Webpack Version; (Included with Next.js)
Description;
I encountered an issue while trying to compile a Next.js project that uses Stylex for styling. The build process. Displays an error message stating that only static values can be used inside the
stylex.create()function call. This problem occurs even though I followed the documentation, which instructs to define variables usingstylex.defineVars()and use them withinstylex.create().like so:
and used it like so:
Steps to Reproduce;
stylex.defineVars()in a file calledtokens.stylex.ts.stylex.create()call in a component.buildcommand to compile the project.Expected Result;
The project should successfully compile, with Stylex processing the CSS variable definitions and applying them as intended.
Actual Result;
The build process encounters an error that states;
This error indicates that there might be dynamic values being passed to
stylex.create()which is not supported.Additional Information;
The Next.js configuration has been customized to utilize the
@stylexjs/webpack pluginfor StyleX.Due to the issue, with Google Fonts and the Next.js StyleX plugin it was decided to use the Webpack plugin
Note: It is observed that the compilation works when
stylex.create()is used with a function that returns the style object, as shown below:However, this approach is contrary to the examples provided in the Stylex documentation where
stylex.create()is directly given an object. The expected usage, as per the documentation, which is currently not working, is:This inconsistency between the documentation and the actual working solution suggests a potential issue with the library's handling of variable definitions within
stylex.create()calls.Thanks for reviewing the issue, we are looking forward to use this in our app,
Samplead Team