After installing fork-ts-checker-webpack-plugin builds start failing, we get a runtime error:
ERROR in [internal] INTERNAL ERROR: Cannot read property 'length' of undefined stack trace: TypeError: Cannot read property 'length' of undefined at unescapeLeadingUnderscores
stack trace:
TypeError: Cannot read property 'length' of undefined
at unescapeLeadingUnderscores (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:13568:19)
at Object.idText (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:13572:16)
at typeToTypeNodeHelper (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35285:57)
at addPropertyToElementList (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35679:59)
at createTypeNodesFromResolvedType (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35629:25)
at createTypeNodeFromObjectType (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35459:35)
at createAnonymousTypeNode (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35411:42)
at typeToTypeNodeHelper (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35319:28)
at C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35113:106
at withContext (C:\Users\mforman\Development\Specs\node_modules\typescript\lib\typescript.js:35154:37)
Successful build
On webpack.config.js:
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
plugins: [
//other code
new ForkTsCheckerWebpackPlugin(),
],
then - npm run build results the above error.
@johnnyreilly Any idea what can causes this error? Thanks!
I'm afraid not - does it present if you use this setup:
https://github.com/TypeStrong/ts-loader/tree/master/examples/fork-ts-checker-webpack-plugin
This is not a fork-ts-checker-webpack-plugin error message, but something within typescript itself.
Other people are experiencing similar things under different circumstances, see many of these issues.
Just a guess: maybe TS or some other dependency was updated while installing fork-ts-checker-webpack-plugin?
Please try it again while commenting out the new ForkTsCheckerWebpackPlugin(), line in your plugins.
If the bug persists, it is something with some other dependency (probably in combination with a weird type or some configuration).
If the bug is gone, it might be something to do with how we call typescript internally. We'll see how to debug that if we have verified the situation.
@phryneas Thanks for your reply.
Other dependencies were not updated while installing fork-ts-checker-webpack-plugin.
While commenting out the new ForkTsCheckerWebpackPlugin() line, the bug is gone and the build success. Please advise.
Thank you!
First thing to check: do you get different results using useTypescriptIncrementalApi: true vs useTypescriptIncrementalApi: false?
Also, your project isn't open source per chance so I could take a look?
Yes, using new ForkTsCheckerWebpackPlugin({useTypescriptIncrementalApi: false}), the build success and the bug is gone.
unfortunately not:(
Thank you.
Could you at least share your tsconfig.json?
useTypescriptIncrementalApi: false is something we'd like to deprecate in the future, so it would be great if we could somehow reproduce this.
And I believe it might be something how TS internally handles the config differently between createCompilerHost and createWatchCompilerHost in certain cases.
Sure, please see below:
tsconfig.json
{
"compilerOptions": {
// Allow importing like `import React from 'react'`
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"module": "esNext",
// Resolve modules using Node-resolution algorithm
"moduleResolution": "node",
// Set React as the JSX factory
"jsx": "react",
// Include typings from built-in lib declarations
"lib": ["es2019", "dom", "dom.iterable", "webworker"],
// Include module source maps for debugging
"sourceMap": true,
"baseUrl": ".",
"skipLibCheck": true,
"target": "ES2020"
},
"exclude": ["node_modules"]
}
@phryneas Hi,
Have you came up with anything?
Thanks!
Sorry, but not really. That's a really standard tsconfig.json.
I still believe this might be a typescript-internal error that's just only triggered in a watched build or something similar (the full stacktrace doesn't touch a single file from fork-ts-checker-webpack-plugin)
Could you try doing a tsc --watch on the command line and see if it triggers there, too?
@phryneas, Yes, it triggers there too:
$ npx tsc --watch
[10:36:59 AM] Starting compilation in watch mode...Cannot read property 'length' of undefined
Then this is a TypeScript bug. I suggest you open an issue over in https://github.com/microsoft/typescript - and mention that it only happens when using the watch API (I guess a normal tsc without --watch will run successfully for you)
@phryneas Thank you for your assistance, thanks to your comments I was able to figure out what triggers the issue.
Thanks so much!
Thank you for your assistance, thanks to your comments I was able to figure out what triggers the issue.
Thanks so much!
@mforman1 Could you please share what triggered this issue and what was your solution? I would really appreciate your help. Cheers. :)
I had a similar issue and was able to track it down to a typescript definition file? https://github.com/diegomura/react-pdf/pull/833
Most helpful comment
@mforman1 Could you please share what triggered this issue and what was your solution? I would really appreciate your help. Cheers. :)