Repository navigation
TypeError: Cannot read property 'text' of undefined #8216
Copy link
Copy link
Closed
Labels
P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfulImpacts a large percentage of users; if a workaround exists it is partial or overly painfulneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is neededtype: bug/fix
Description
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
Angular CLI: 1.5.0-rc.5
Node: 8.8.1
OS: darwin x64
Angular: 5.0.0-rc.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
@angular/cli: 1.5.0-rc.5
@angular-devkit/build-optimizer: 0.0.31
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0-rc.5
@schematics/angular: 0.0.48
typescript: 2.4.2
webpack-bundle-analyzer: 2.9.0
webpack: 3.8.1
Repro steps.
in my package, anyway
ng serve --ssl --public-host=//localhost:4200/sockjs-node/ --deploy-url=//localhost:4200/ --serve-path=/
make a trivial change to a template
The log given by the failure.
ERROR in Error: TypeError: Cannot read property 'text' of undefined
at getErrorSpanForNode (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:7304:40)
at createDiagnosticForNodeInSourceFile (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:7229:20)
at Object.createDiagnosticForNode (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:7225:16)
at error (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:27167:22)
at resolveExternalModule (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:28226:17)
at resolveExternalModuleNameWorker (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:28213:20)
at Object.getExternalModuleFileFromDeclaration (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:47978:32)
at tryGetModuleNameFromDeclaration (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:15517:50)
at Object.getExternalModuleNameLiteral (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:15481:20)
at createRequireCall (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:61248:33)
at visitExportDeclaration (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:61310:45)
at sourceElementVisitor (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:61091:28)
at Object.visitNodes (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:49280:48)
at transformCommonJSModule (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:60834:40)
at transformSourceFile (/Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:60808:27)
at /Users/karp/Documents/git/bgg/geekui2/node_modules/typescript/lib/typescript.js:2492:86
Desired functionality.
Successful compilation
Mention any other details that might be useful.
After the first build, everything works correctly. But a trivial change to a template or a change to whitspace in a ts file gives the error shown.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfulImpacts a large percentage of users; if a workaround exists it is partial or overly painfulneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is neededtype: bug/fix
Activity
karptonite commentedon Oct 31, 2017
Sure, go ahead. I'd love for it to build faster! Did you mean that previously my AOT builds with these would have failed in runtime, but now they work?
Also, if anyone else needs access to that repo, let me know--I can quickly add more public keys.
filipesilva commentedon Oct 31, 2017
I'm not sure if it would have failed before. I suspect that maybe the library was being built with the app. But it could break anytime because the TS version your app uses is not necessarily the same as the one the library uses.
Now the non-AOT mode sees the file isn't part of your TS project and fails. But the AOT build seems to be emitting the file still, which is something I'll have to bring up with the compiler team.
avbentem commentedon Oct 31, 2017
Ah, my bad (I feel really stupid), you were (of course) referring to Angular CLI RC8, not Angular 5 RC8... So:
For
@angular/cli: 1.5.0-rc.8all fine for--aot,--no-aotand none of these (which defaults to--aotthen). Nice!(Angular 5.0.0-rc.9, Angular CLI 1.5.0-rc.8 on Windows 7. And totally as an aside: https://github.com/angular/angular-cli/releases shows me RC6 on top of the page (screenshot), but also a link to "Show 2 newer tags", which indeed then reveals RC7 and RC8 (screenshot). Maybe hidden as there are no release comments?)
filipesilva commentedon Oct 31, 2017
@avbentem glad to hear that version sorts it for you 👍
You're right, we forgot to add the release notes to those two. I'll get on it.
karptonite commentedon Nov 1, 2017
@filipesilva Any official word on this issue: #8216 (comment) ? The packages that are breaking no-aot (but not aot), and which maybe aren't really working with aot?
filipesilva commentedon Nov 1, 2017
@karptonite I added a comment in #8263 to give an update on what's going on:
To give you all an update on the issue, @hansl is trying to work with the library authors of known problematic libraries to sort these issues out.
karptonite commentedon Nov 1, 2017
@filipesilva In that case, I'm closing this issue in favor of #8263. The original issue with "Cannot read property 'text'..." on rebuild in AOT is fixed, and it looks like the other issue is where you are handling the problematic libraries.
By the way, thanks for the kind words about BoardGameGeek!
DaSchTour commentedon Dec 21, 2017
Was there something reverted regarding this issue? I'm getting this error with 1.6.2
isaacplmann commentedon Dec 21, 2017
I'm getting this error in 1.6.2 as well.
clydin commentedon Dec 21, 2017
Can you open a new issue and provide the full command line used that causes the error?
trollkotze commentedon Mar 21, 2018
#metoo @1.7.2
haoliangwu commentedon Mar 23, 2018
get same error in angular-cli@1.7.2
luchillo17 commentedon Apr 5, 2018
Getting the same in
@angular/cli@1.7.3luchillo17 commentedon Apr 6, 2018
I've tested each version from
1.6.2to1.7.3and they don't work with my current project, the only workaround for me is to downgrade to1.6.1.rynrn commentedon Apr 12, 2018
+1 angular-cli@1.7.2
bmts commentedon Apr 20, 2018
+1 angular-cli@1.7.4
luchillo17 commentedon Apr 20, 2018
Easy fix for now is
--no-aot.avbentem commentedon May 16, 2018
Maybe obvious, but just in case: I am no longer getting this error in Angular CLI 6.0.x (with AOT in an Angular 6 project).
shaizel commentedon Jun 28, 2018
Have been struggling with this issue for a couple of days now and finally solved it after no other solution worked for me.
Like in all the other cases I've read here and in other places, every other compilation would fail with the message "Cannot read property 'text' of undefined" and the stacktrace points to different functions in typescript.js. .
I've opened the file typescript.js and went to the function "transformCommonJSModule" that appears in the error's stack trace. I've added console.log("####", node) to the beginning of the function, logging the function's parameter, node.
I then proceeded to recompile the project.
When I got the compilation bug again, I went to the last appearance of "####" in the log and in the "node" object's content there were several fields called "fileName". They all pointed to a file called "something.service.factory.js". The file something.service.ts contains an injectable service in my application.
I went to that file and checked what changes I made to it when the bug first appeared.
Turns out I've added a method to this service and made it public and static. For some reason, the compiler didn't like it half of the time. I removed the "static" notation and fixed all references to it and it solved the problem.
It seems this bug can be caused by different things. The process I described above can help narrow down what the cause is.
Good luck!
k0nG commentedon Feb 8, 2019
Thanks, @shaizel for your suggestion it helped me track down what was causing this error for me.
For anyone like me coming to this and running a hybrid AngularJS and Angular application. Try removing the
@types/angulardependency from yourpackage.jsonicorne commentedon Jun 21, 2019
I'm running into this, what specifically in @types/angular is breaking thinks @k0nG ?
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.