Skip to content

Macaron API calls are not being processed when present in a file ending with .css.ts #78

Open
@ymeine

Description

@ymeine

If I try putting style definitions in a file whose name ends with .css.ts, like for instance styles.css.ts, Macaron does not process them, leading to a runtime error:

Error: An unexpected error occurred undefined:3069:5
Uncaught Error: Styles were unable to be assigned to a file. This is generally caused by one of the following:

- You may have created styles outside of a '.css.ts' context
- You may have incorrect configuration. See https://vanilla-extract.style/documentation/getting-started
    getFileScope http://localhost:5173/node_modules/.vite/deps/@macaron-css_core.js?v=b2e50fad:3069
    generateIdentifier http://localhost:5173/node_modules/.vite/deps/@macaron-css_core.js?v=b2e50fad:4658
    style http://localhost:5173/node_modules/.vite/deps/@macaron-css_core.js?v=b2e50fad:4911
    <anonymous> http://localhost:5173/src/styles.css.ts:2
@macaron-css_core.js:3069:11

Example of file:

import {style} from '@macaron-css/core';

export const block = style({
	background: 'green',
});

Why would this be a valid use case?

I know this can seem counterintuitive to do so since the inherent goal of Macaron is to be able to co-locate styles with the code consuming them. But I think it doesn’t mean it should force to do so, but rather just enable.

There can still be valid use cases to group style definitions in dedicated files (in addition to having co-located styles thanks to Macaron) and to be willing to name those files with a .css.ts extension for clarity. The thing is, I don’t see why it should not be possible with Macaron.

Also, it can help for a smoother transition, since it’s much easier to globally replace @vanilla-extract/css imports with @macaron-css/core, rather than having to move the entire code into different files.

Now, one could say I could use @vanilla-extract/css directly in those files, but:

  • it would feel highly inconsistent, and require installing vanilla-extract and configuring it explicitly in addition to Macaron
  • it is actually not possible to mix both Macaron and vanilla-extract, see issue Cannot use vanilla-extract along with Macaron #77

Why it happens?

I see why it behaves that way currently, but I think it could be changed, though by experience I understand dealing with Vite and vanilla-extract can be tricky.

I guess it would be easy to decide to process that file, but probably less to tell vanilla-extract to ignore it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions