vite-plugin-stylex icon indicating copy to clipboard operation
vite-plugin-stylex copied to clipboard

Cannot use variables

Open aspizu opened this issue 1 year ago • 5 comments

[vite] Internal server error: /home/aspizu/Documents/Projects/stylex-components/src/Base.tsx: Only static values are allowed inside of a stylex.create() call.
  Plugin: vite-plugin-stylex
import react from "@vitejs/plugin-react"
import {defineConfig} from "vite"
import {stylexPlugin} from "vite-plugin-stylex-dev"

export default defineConfig({
    plugins: [
        react(),
        stylexPlugin({
            unstable_moduleResolution: {
                type: "commonJS",
                rootDir: "/src",
            },
        }),
    ],
    build: {
        target: "esnext",
    },
})
import {colors, fontFamily} from "./tokens.stylex.ts"
import * as stylex from "@stylexjs/stylex"

export const fontFamily = stylex.defineVars({
    sans: "Inter",
    serif: "Merriweather",
    mono: "Cascadia Code",
})

export const colors = stylex.defineVars({
    background: "#000000",
    foreground: "#ffffff",
})

aspizu avatar Apr 09 '24 10:04 aspizu

minimal reproduction?

nonzzz avatar Apr 09 '24 10:04 nonzzz

this is all i have

aspizu avatar Apr 09 '24 12:04 aspizu

https://github.com/HorusGoul/vite-plugin-stylex has the exact same issue

aspizu avatar Apr 09 '24 12:04 aspizu

https://github.com/HorusGoul/vite-plugin-stylex has the exact same issue

using both, didn't run into this problem by following the docs about importing variables from .stylex.js files only. Maybe you imported other things into the stylex.create() call? Try to create a reproduction.

predaytor avatar Apr 09 '24 16:04 predaytor

I couldn't find any reproduction for the issue, AFAIk setting 'rootDir' manually is not necessary.

nonzzz avatar Apr 10 '24 07:04 nonzzz