You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invisible name clash when importing a css file in same-named JS file #912
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.
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.
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.
Activity
WoodyWoodsta commentedon Apr 14, 2026
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.WoodyWoodsta commentedon Apr 14, 2026
One more finding: when
css.inject = falseandformat = 'commonjs', therequire(css-filename.js)is still present in the output.sxzzbot commentedon Nov 2, 2026
Fixed in #1114, which will ship in the next tsdown release (after v0.23.4).
unbundle: trueno longer keeps arequire()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.Card2.cjsname comes from Rolldown stripping.cssfrom[name], fixed in fix(preserve-modules): keep non-JS extensions in [name] rolldown#11410. tsdown depends onrolldownwith~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, updaterolldownto pick it up.