TypeScript Version: 2.3.1
Note: This does not occur in 2.3.0
Code
I've been unable to isolate what is causing this in our code base
Actual behavior:
Module build failed: TypeError: Cannot read property 'flags' of undefined
at Object.isExternalModuleSymbol (/project/node_modules/typescript/lib/typescript.js:70969:40)
at getExportInfo (/project/node_modules/typescript/lib/typescript.js:74881:23)
at exportInfo (/project/node_modules/typescript/lib/typescript.js:74841:34)
at getExport (/project/node_modules/typescript/lib/typescript.js:74790:36)
at Object.getImportOrExportSymbol (/project/node_modules/typescript/lib/typescript.js:74761:53)
at getImportOrExportReferences (/project/node_modules/typescript/lib/typescript.js:75618:56)
at getReferencesAtLocation (/project/node_modules/typescript/lib/typescript.js:75559:17)
at getReferencesInContainer (/project/node_modules/typescript/lib/typescript.js:75513:21)
at getReferencedSymbolsForSymbol (/project/node_modules/typescript/lib/typescript.js:75213:21)
at Object.getReferencedSymbolsForNode (/project/node_modules/typescript/lib/typescript.js:75172:24)
at Object.getReferenceEntriesForNode (/project/node_modules/typescript/lib/typescript.js:74988:58)
at getSemanticDocumentHighlights (/project/node_modules/typescript/lib/typescript.js:73804:57)
at Object.getDocumentHighlights (/project/node_modules/typescript/lib/typescript.js:73791:29)
at Object.getDocumentHighlights (/project/node_modules/typescript/lib/typescript.js:86205:42)
at NoUseBeforeDeclareWalker.validateUsageForVariable (/project/node_modules/tslint/lib/rules/noUseBeforeDeclareRule.js:113:47)
at NoUseBeforeDeclareWalker.visitNamedImports (/project/node_modules/tslint/lib/rules/noUseBeforeDeclareRule.js:92:18)
at NoUseBeforeDeclareWalker.SyntaxWalker.visitNode (/project/node_modules/tslint/lib/language/walker/syntaxWalker.js:421:22)
at NoUseBeforeDeclareWalker.ScopeAwareRuleWalker.visitNode (/project/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.js:58:36)
at /project/node_modules/tslint/lib/language/walker/syntaxWalker.js:523:63
at visitNode (/project/node_modules/typescript/lib/typescript.js:14712:20)
at Object.forEachChild (/project/node_modules/typescript/lib/typescript.js:15010:21)
at NoUseBeforeDeclareWalker.SyntaxWalker.walkChildren (/project/node_modules/tslint/lib/language/walker/syntaxWalker.js:523:12)
at NoUseBeforeDeclareWalker.SyntaxWalker.visitNode (/project/node_modules/tslint/lib/language/walker/syntaxWalker.js:517:22)
at NoUseBeforeDeclareWalker.ScopeAwareRuleWalker.visitNode (/project/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.js:58:36)
at /project/node_modules/tslint/lib/language/walker/syntaxWalker.js:523:63
at visitNode (/project/node_modules/typescript/lib/typescript.js:14712:20)
at Object.forEachChild (/project/node_modules/typescript/lib/typescript.js:15006:21)
at NoUseBeforeDeclareWalker.SyntaxWalker.walkChildren (/project/node_modules/tslint/lib/language/walker/syntaxWalker.js:523:12)
at NoUseBeforeDeclareWalker.SyntaxWalker.visitImportDeclaration (/project/node_modules/tslint/lib/language/walker/syntaxWalker.js:137:14)
at NoUseBeforeDeclareWalker.visitImportDeclaration (/project/node_modules/tslint/lib/rules/noUseBeforeDeclareRule.js:79:49)
I suggest you update tslint to at least 5.0.0. The way how no-use-before-declare was implemented resulted in several problems. Therefore the rule was completely rewritten for [email protected]
I see this same error when using the rule "no-unused-variable": true with tslint 5.4.3 and tsc 2.4.1.
"TypeError: Cannot read property 'flags' of undefined" with no-unused-variable rule.
TypeScript 2.4.1
https://unpkg.com/[email protected]/
TSlint 5.5.0
https://unpkg.com/[email protected]/
TypeError: Cannot read property 'flags' of undefined
at Object.getCheckFlags (/PROJECT/node_modules/typescript/lib/typescript.js:10137:22)
at getTypeOfSymbol (/PROJECT/node_modules/typescript/lib/typescript.js:30957:20)
at getTypeOfNode (/PROJECT/node_modules/typescript/lib/typescript.js:47329:24)
at Object.getTypeAtLocation (/PROJECT/node_modules/typescript/lib/typescript.js:26823:31)
at getImplicitType (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:269:24)
at cb (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:259:20)
at visitEachNode (/PROJECT/node_modules/typescript/lib/typescript.js:15956:30)
at Object.forEachChild (/PROJECT/node_modules/typescript/lib/typescript.js:16143:24)
at cb (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:264:19)
at visitNode (/PROJECT/node_modules/typescript/lib/typescript.js:15944:20)
I also randomly experience it when using Monaco editor:
TypeError: Cannot read property 'flags' of undefined
at Object.ve [as isExternalModuleSymbol] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:56)
at p (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at s (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at i (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at Object._ [as getImportOrExportSymbol] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at T (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at x (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at k (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at i (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at Object.n [as getReferencedSymbolsForNode] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at Object.ve [as isExternalModuleSymbol] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:56)
at p (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at s (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at i (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at Object._ [as getImportOrExportSymbol] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at T (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at x (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at k (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at i (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at Object.n [as getReferencedSymbolsForNode] (/_vendor/monaco/0.9.0/vs/language/typescript/lib/typescriptServices.js:58)
at /_vendor/monaco/0.9.0/vs/editor/editor.main.js:31
(anonymous) @ /_vendor/monaco/0.9.0/vs/editor/editor.main.js:31
on windows:
ran:
ng build --aot -prod
I still see this in Angular 5, fresh new angular 5 package impossible to build for production,
angular cli: ~1.7.4,
angular compiler-cli: "^5.2.0",
"tslint": "~5.9.1",
"typescript": "^2.5.0"
error:
TypeError: Cannot read property 'flags' of undefined
tried to upgrade to angular 6, updated cli, still had issues, went back to angular 5, started a new project from fresh to test, and I saw the same error, this angular 5 has some serious issues, and even some persisted still in angular 6.
After all of all your hard work, at the end, you will not be able to build your solution for production. Good luck with it mate.
So went back down to angular 5:
I then upgraded typescript tried up to [email protected],
each time I ran:
ng build --aot -prod
still got the same error.
so tried:
npm install [email protected]
tried to build for production again:
I got a different error response:
ERROR in Cannot read property 'kind' of undefined
Left the Angular project on hold, moved onto react, no problems so far, so sad. I used to like Angular.
IF anyone knows a solution let me know, I am hoping for a miracle.
Angular team, please keep things simple mate, too clever to complicate for no reason = task paralysis.
Keep things necessary, You can live longer :) and happier, stress free mate :)
Most helpful comment
"TypeError: Cannot read property 'flags' of undefined" with
no-unused-variablerule.TypeScript
2.4.1https://unpkg.com/[email protected]/
TSlint
5.5.0https://unpkg.com/[email protected]/