-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
TypeScript Version: 3.7.2
Search Terms:
- charCodeAt
- path.charCodeAt is not a function TSINTERNAL_ERROR
- getDirectoryOrExtensionlessFileName
- getEncodedRootLength
Code
TypeScript/src/compiler/moduleSpecifiers.ts
Line 337 in 7c14aff
const mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main; |
Expected behavior:
To handle cases in which mainFileRelative
resolves to other than a string
.
Actual behavior:
Crashes and unexpected bugs under some conditions when mainFileRelative
resolves to for example an array. The result is then handled by getEncodedRootLength
at:
TypeScript/src/compiler/path.ts
Line 117 in 7c14aff
function getEncodedRootLength(path: string): number { |
Which end up calling charCodeAt
in something that is not a string:
TypeScript/src/compiler/path.ts
Line 119 in 7c14aff
const ch0 = path.charCodeAt(0); |
Failed to compile.
[internal]
TypeScript error in [internal](undefined,undefined):
path.charCodeAt is not a function TSINTERNAL_ERROR
at: getDirectoryOrExtensionlessFileName
path: /***/***/ts-weird-bug/node_modules/csv-parse/lib/index.d.ts
content of types field: [ "./lib/index.d.ts", "./lib/sync.d.ts" ]
at: getEncodedRootLength
TypeError: path.charCodeAt is not a function
at getEncodedRootLength (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:5830:27)
at isRootedDiskPath (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:5742:16)
at Object.toPath (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:6163:36)
at getDirectoryOrExtensionlessFileName (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:99655:49)
at tryGetModuleNameAsNodeModule (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:99631:70)
at /***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:99451:88
at Object.mapDefined (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:704:30)
at Object.getModuleSpecifiers (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:99451:29)
at getSpecifierForModuleSymbol (/***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:37232:62)
at /***/***/ts-weird-bug/node_modules/typescript/lib/typescript.js:37098:39
Playground Link:
A repo that reproduces the issue: https://github.com/juanmait/ts-weird-bug. All the details are in the readme. Unfortunately the issue happen due to a combination of factors. A third party library that ships an invalid value for the field types
in the package.json, some trickery made by react-scripts
and this typescript bug (?
Related Issues: