ts-migrate
ts-migrate copied to clipboard
Error: Failed to add @ts-expect-error within template expression.
Who has encountered this problem?
TypeScript version: 4.0.2
Initialized tsserver project in 21864.213ms.
Start...
[strip-ts-ignore] Plugin 1 of 13. Start...
[strip-ts-ignore] Finished in 9671.452ms.
[hoist-class-statics] Plugin 2 of 13. Start...
[hoist-class-statics] Finished in 3010.238ms.
[react-props] Plugin 3 of 13. Start...
[react-props] Finished in 8997.580ms.
[react-class-state] Plugin 4 of 13. Start...
[react-class-state] Finished in 1146.588ms.
[react-class-lifecycle-methods] Plugin 5 of 13. Start...
[react-class-lifecycle-methods] Finished in 1230.168ms.
[react-default-props] Plugin 6 of 13. Start...
[react-default-props] Finished in 125.415ms.
[react-shape] Plugin 7 of 13. Start...
[react-shape] Finished in 74.528ms.
[declare-missing-class-properties] Plugin 8 of 13. Start...
[declare-missing-class-properties] Finished in 1527402.648ms.
[member-accessibility] Plugin 9 of 13. Start...
[member-accessibility] Finished in 251.822ms.
[explicit-any] Plugin 10 of 13. Start...
[explicit-any] Finished in 2598251.268ms.
[eslint-fix] Plugin 11 of 13. Start...
[eslint-fix] Finished in 5068.773ms.
[ts-ignore] Plugin 12 of 13. Start...
Error: [ts-ignore][src/cards/XXX.tsx] Error:
Error: Failed to add @ts-expect-error within template expression.
at /node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:69:27
at Array.forEach (<anonymous>)
at getTextWithIgnores (/node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:24:17)
at Object.run (/node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:15:16)
at Object.migrate (/node_modules/ts-migrate-server/build/src/migrate/index.js:73:46)
at async Object.handler (/node_modules/ts-migrate/build/cli.js:128:22)
Error: [ts-ignore][src/cards/+IndustryDetail/IndustryMarketMovement/components/HotChart.tsx] Error:
Error: Failed to add @ts-expect-error within template expression.
at /node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:69:27
at Array.forEach (<anonymous>)
at getTextWithIgnores (/node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:24:17)
at Object.run (/node_modules/ts-migrate-plugins/build/src/plugins/ts-ignore.js:15:16)
at Object.migrate (/node_modules/ts-migrate-server/build/src/migrate/index.js:73:46)
at async Object.handler (/node_modules/ts-migrate/build/cli.js:128:22)
haven't seen this before. Could you please share source code or an example, where it failed?
I get this when converting styled components:
export const ButtonStyled = styled.button `
// It tries to add @ts-expect-error here
${props => props.isSmall &&
css `
${SmallButtonStyles}
`}
`;
Been getting this Error: Failed to add @ts-expect-error within template expression.
as well. In my case this only happens when having the addConversionsPlugin
enabled, but it might happen due to other text/line/formatting changes as well. In my case it actually tries to add a @ts-expect-error
about setTimeout
not being defined (had the the DOM lib disabled), but the offending line did nothing with setTimeout
. As if the diagnostic
was not referring to the correct position. Which is possible, as some empty lines are stripped and some formatting changed occur due to the transformations done by addConversionsPlugin
.
I am not using the ts-migrate
command directly (or ts-migrate-server
for that matter), but my code is heavily based on that code, I found that in this ts-migrate-server/src/migrate/index.ts#L85 there was an issue. The sourceFile
changes, and the current sourceFile and diagnostics might be incorrect. Fixed this by updating the sourceFile
const in the plugins/sourceFiles loops to update with the return value from project.updateSourceFile
. This might have already been an issue before, but this commit of ts-migrate
has only made it worse.
Hope this helps you, or helps in creating a fix.