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
Add an export to the file using ESM-like syntax (e.g. export default { cjs: true };)
Run biome format .
Get parsing error:
./src/tests/data/cjs.cts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Illegal use of an export declaration outside of a module
> 1 │ export default { cjs: true };
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
i not allowed inside scripts
Biome should recognize that this is a typescript file (.cts not .cjs), and therefore ESM-like syntax is allowed.
Perhaps more generally, maybe it should recognize that some other transpiler will be touching this code before execution, so seemingly invalid code is actually allowed and formatting should proceed as usual.
To be clear, the intention of this error is correct. If I were using import/export in a .cjs file (or a .js file with { "type": "commonjs" }) I would expect this error to occur.
In the Biome playground I needed to set the source type to Script to get the failure, which explicitly disables the ability to enable typescript. I suspect there is some failure to recognize .cts as module+typescript, rather than commonjs.
Code of Conduct
I agree to follow Biome's Code of Conduct
The text was updated successfully, but these errors were encountered:
Environment information
What happened?
index.cts
(this is a forced commonjs file, but it is typescript so we are allowed to used use ESM-like syntax: https://www.typescriptlang.org/play?module=1#code/KYDwDg9gTgLgBAE2AMwIYFcA28DecDGAVgM4BccMU6wcAvgNxA).export default { cjs: true };
)biome format .
See playground: https://biomejs.dev/playground/?code=ZQB4AHAAbwByAHQAIABkAGUAZgBhAHUAbAB0ACAAewAgAGMAagBzADoAIAB0AHIAdQBlACAAfQA7AAoA&typescript=false&jsx=false&script=true
Expected result
Biome should recognize that this is a typescript file (
.cts
not.cjs
), and therefore ESM-like syntax is allowed.Perhaps more generally, maybe it should recognize that some other transpiler will be touching this code before execution, so seemingly invalid code is actually allowed and formatting should proceed as usual.
To be clear, the intention of this error is correct. If I were using
import
/export
in a.cjs
file (or a.js
file with{ "type": "commonjs" }
) I would expect this error to occur.In the Biome playground I needed to set the source type to Script to get the failure, which explicitly disables the ability to enable typescript. I suspect there is some failure to recognize
.cts
as module+typescript, rather than commonjs.Code of Conduct
The text was updated successfully, but these errors were encountered: