nonzzz / vite-plugin-stylex

an unofficial @stylexjs vite support
MIT License
50 stars 4 forks source link

Cannot use variables #16

Open aspizu opened 6 months ago

aspizu commented 6 months ago
[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",
})
nonzzz commented 6 months ago

minimal reproduction?

aspizu commented 6 months ago

this is all i have

aspizu commented 6 months ago

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

predaytor commented 6 months ago

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.

nonzzz commented 5 months ago

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