TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

tsc crash with `Error: start < 0` in a specific config

Open yume-chan opened this issue 1 year ago • 1 comments

🔎 Search Terms

crash createTextSpan

🕗 Version & Regression Information

  • This is a crash

⏯ Playground Link

No response

💻 Code

https://github.com/yume-chan/ts-crash

This is a minimal repro with only 15 lines across 3 files.

🙁 Actual behavior

pnpm i
npx tsc

Output:

# npx tsc
/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:11034
    throw new Error("start < 0");
    ^

Error: start < 0
    at createTextSpan (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:11034:11)
    at createTextSpanFromBounds (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:11042:10)
    at getErrorSpanForNode (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:13589:10)
    at createDiagnosticForNodeFromMessageChain (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:13419:16)
    at resolveExternalModule (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:48013:31)
    at resolveExternalModuleNameWorker (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:47907:61)
    at resolveExternalModuleName (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:47904:12)
    at getSymbolAtLocation (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:84201:18)
    at Object.getSymbolAtLocation (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:45191:21)
    at getReferencedFilesFromImportLiteral (/root/ts-crash/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsc.js:121837:28)

Node.js v21.6.2

🙂 Expected behavior

No crash.

Additional information about the issue

Reproducible in both 5.4.5 and 5.5.0-dev.20240520

yume-chan avatar May 21 '24 05:05 yume-chan

You have a synthetic import to solid-js/jsx-runtime here. It's an ESM file but you are importing it from a CJS one. TS crashes when trying to raise 1479 diagnostic:

The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_reference_1479", `The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("{0}")' call instead.

The reason it crashes here is that you have composite: true. This option enables incremental compilation and that eagerly calls resolveExternalModuleName from getReferencedFiles.

Andarist avatar May 21 '24 09:05 Andarist

Noticed this while trying to run tsc -w on a project with JSR as the package manager. It also seemed to be crashing with the JSX import source, "jsxImportSource": "@hono/hono/jsx".

Offroaders123 avatar Aug 27 '24 17:08 Offroaders123

@Offroaders123 The fix is included in 5.6.0 and above (or any nightly after Jun 24)

iisaduan avatar Aug 27 '24 20:08 iisaduan