Skip to content

Invisible name clash when importing a css file in same-named JS file #912

Closed

Description

@WoodyWoodsta

Reproduction link or steps

https://stackblitz.com/edit/github-mcmfinbh?file=tsdown.config.mts

What is expected?

Can import a css file which is the same name as a js file.

What is actually happening?

When importing a css file which has the same name as the JS file, the output incudes he JS file name with 2 appended, and the output includes a require to the original file name (which does not exist).

Any additional comments?

I'm not sure if commonjs is to blame, or something else.

Activity

  1. added theissue type on Apr 14, 2026
  2. WoodyWoodsta commented on Apr 14, 2026

    @WoodyWoodsta
    Author

    In fact, I think there is something more to this as well, which is that when you import a css file, it for some reason is output as a require('css-filename.js'), when instead it should be preserving the require as a css file for consuming bundlers to pick up and manage.

    When switching to esm output, and making sure that css.inject = true, the correct import is included in the output - so it seems to be isolated to commonjs.

  3. WoodyWoodsta commented on Apr 14, 2026

    @WoodyWoodsta
    Author

    One more finding: when css.inject = false and format = 'commonjs', the require(css-filename.js) is still present in the output.

  4. added
    bugSomething isn't working
    and removed on Oct 28, 2026
  5. sxzzbot commented on Nov 2, 2026

    @sxzzbot
    Collaborator

    Fixed in #1114, which will ship in the next tsdown release (after v0.23.4).

    • CJS output with unbundle: true no longer keeps a require() to the removed CSS chunk, so it loads again. This happened with any CSS file name, not only when it matched a JS file. Until the release, ESM output isn't affected.
    • The Card2.cjs name comes from Rolldown stripping .css from [name], fixed in fix(preserve-modules): keep non-JS extensions in [name] rolldown#11410. tsdown depends on rolldown with ~1.2.15, so it's resolved automatically by the next Rolldown 1.2.x release, with no tsdown change needed. If you have a lockfile, update rolldown to pick it up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcss

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions