NPM script stops working when tsconfig extends @sapphire/ts-config

My npm package has a simple build script:
"prebuild": "rimraf dist types",
"build": "tsc",
"prebuild": "rimraf dist types",
"build": "tsc",
When extending @sapphire/ts-config on my tsconfig.json , it stops working. Using typescript^5.3.2 and rimraf^5.0.5. Strangely enough, running tsc in the same working directory works as expected... Full tsconfig.json:
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "NodeNext",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"declarationMap": true,
"importHelpers": true
}
}
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "NodeNext",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"declarationMap": true,
"importHelpers": true
}
}
Solution:
to your prebuild add tsconfig.tsbuildinfo, that'll probably fix it. It's the cache file for incremental builds which are enabled by the config.
Jump to solution
7 Replies
Favna
Favna12mo ago
Can you elaborate on what you mean with "stops working" if you mean that it errors, remove module": "NodeNext", from the config. @sapphire/ts-config sets it to node16 which is the current latest. Also you can remove a lot of your own config as it's already set by the sapphire one. You can find references of what sapphire sets in your node_modules or on github
Teixeira
TeixeiraOP12mo ago
The scripts don't error, but they act very strangely: - The first time I execute it (before any build files are created) it does nothing. No errors are thrown either. - If I then simply execute tsc in the same working directory, it will generate build files as it should. - If I then run npm run build, it will work flawlessly, deleting the existing dist and types directories and then generating new build files. - If I then run npm run build again, it will delete the dist and types directories, but won't generate any new build files. No errors are thrown. - Any subsequent runs do nothing (like in the first step, since the dist and types directories were deleted it's back from the start)
Solution
Favna
Favna12mo ago
to your prebuild add tsconfig.tsbuildinfo, that'll probably fix it. It's the cache file for incremental builds which are enabled by the config.
Teixeira
TeixeiraOP12mo ago
Yep that was it... This was driving me nuts! Thank you
Teixeira
TeixeiraOP12mo ago
Also managed to cut down the tsconfig to this thanks to your suggestion:
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"declarationDir": "types",
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true
}
}
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"declarationDir": "types",
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true
}
}
Favna
Favna12mo ago
huh I dont know those bottom 2 I'll have to check what they do
Teixeira
TeixeiraOP12mo ago
Meh, they are a bit "nit-picky" in my opinion, you don't lose much without them, I guess they could be added to sapphire's extra strict tsconfig, if at all
Want results from more Discord servers?
Add your server