Skip to content

rollup-plugin: emitFile rejects relative paths in name field with rolldown 1.0.0-rc.12 #1715

@ericmatthys

Description

@ericmatthys

Description

The renderChunk hook in @vanilla-extract/rollup-plugin passes moduleInfo.id directly as the name field in this.emitFile():

https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/rollup-plugin/src/plugin.ts#L155

const assetId = this.emitFile({
  type: 'asset',
  name: moduleInfo.id,  // can be a relative path like "../styles/src/focusRing.css.ts.vanilla.css"
  source: moduleInfo.meta.css
});

When a .css.ts file imports from another package (e.g. @vanilla-extract/rollup-plugin processing a component that imports tokens from a shared styles package), moduleInfo.id resolves to a relative path like ../styles/src/focusRing.css.ts.vanilla.css.

This worked with rollup/older rolldown versions, but rolldown 1.0.0-rc.12 (shipped with tsdown 0.21.x) now validates that name is neither an absolute nor relative path:

Error: The "fileName" or "name" properties of emitted chunks and assets must be strings
that are neither absolute nor relative paths, received "../styles/src/focusRing.css.ts.vanilla.css".

Suggested Fix

Use path.basename(moduleInfo.id) instead of moduleInfo.id for the name field:

const assetId = this.emitFile({
  type: 'asset',
  name: path.basename(moduleInfo.id),
  source: moduleInfo.meta.css
});

The name field is only used for generating the output filename (via assetFileNames), so stripping the directory prefix should be safe.

Reproduction

  1. Create a package with a .css.ts file that imports from another package's .css.ts file
  2. Build with tsdown >= 0.21.0 (which bundles rolldown 1.0.0-rc.12)
  3. Build fails with the error above

Versions

  • @vanilla-extract/rollup-plugin: 1.5.1 (also reproducible on 1.5.3)
  • tsdown: 0.21.7
  • rolldown: 1.0.0-rc.12

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