stylex icon indicating copy to clipboard operation
stylex copied to clipboard

Aliases not working on windows

Open me16eskandari opened this issue 7 months ago • 5 comments

Describe the issue

In my next.js app I configure stylex.js using postcss

babel.config.js

 const path = require("path");
  
  module.exports = {
    presets: ['next/babel'],
    plugins: [
      [
        '@stylexjs/babel-plugin',
        {
          dev: process.env.NODE_ENV === 'development',
          stylexSheetName: '<>',
          runtimeInjection: false,
          genConditionalClasses: true,
          treeshakeCompensation: true,
          aliases: {
            "@/stylex/*": [path.join(__dirname, "src", "stylex", "*")]
          },
          unstable_moduleResolution: {
            type: 'commonJS',
            rootDir: __dirname,
          },
        },
      ],
    ],
  };

postcss.config.js

const babelConfig = require('./babel.config.js');

module.exports = {
    plugins: {
        '@stylexjs/postcss-plugin': {
            include: [
                './**/*.{js,jsx,ts,tsx}',
                // any other files that should be included
                // this should include NPM dependencies that use StyleX
            ],
            useCSSLayers: false,
            babelConfig
        },
    },
};

and I import colors from src/vars.stylex.ts like this import { colors } from '@/stylex/vars.stylex';

It worked fine on macOs and linux, but got build error on windows SyntaxError: Could not resolve the path to the imported file. Please ensure that the theme file has a .stylex.js or .stylex.ts file extension and follows the rules for defining variariables:

Expected behavior

It should build successfully on windows,

Steps to reproduce

run yarn build on terminal on windows

Test case

No response

Additional comments

No response

me16eskandari avatar May 05 '25 17:05 me16eskandari

Still no one want to answer me?

me16eskandari avatar May 08 '25 08:05 me16eskandari

Thanks for reporting the issue

necolas avatar May 08 '25 10:05 necolas

Piggy backing off this.

I'm using the CLI on windows via a config file. (v.0.14.0) I've tried using the styleXConfig property like it is in the cli example

styleXConfig: {
  aliases: {
    '@/*': ['./source/*'],
  },
},

But that doesn't work.

I get the same error as @me16eskandari

SyntaxError: Could not resolve the path to the imported file. Please ensure that the theme file has a .stylex.js or .stylex.ts file extension and follows the rules for defining variariables

BjornHMS avatar Jul 01 '25 16:07 BjornHMS

A coworker is having the same issue on Windows, while the setup we have perfectly work on unix system.

Could #856 help ?

MoOx avatar Aug 27 '25 13:08 MoOx

Sorry to bother with this issue, but that's actually a simple problem that could happen to people using Windows with typescript aliases, something people are using more and more since various projects setup alias in there default app template. I am not myself using Windows, but some coworkers are and cannot contribute to the project since it's just no building correctly since I introduced stylex (via RSD).

Could you point me where to have a look to resolve this Windows related issue ? This must have to do with path resolving and I am not sure where to look. Also, maybe, as mentioned earlier, it could be nice to know if work done in #856 could help and solve this issue ?

MoOx avatar Oct 15 '25 11:10 MoOx