Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaticSymbolResolver - TypeError: Cannot read property 'length' of undefined #15188

Closed
jt-helsinki opened this issue Mar 15, 2017 · 18 comments
Closed
Assignees
Labels
area: core Issues related to the framework runtime freq2: medium type: bug/fix
Milestone

Comments

@jt-helsinki
Copy link

I'm submitting a ... (check one with "x")

[ x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When trying to do an AOT compilation the following error is received:

Starting compilation using the angular compiler.
Angular compilation done, starting webpack bundling.
TypeError: Cannot read property 'length' of undefined
    at StaticSymbolResolver.resolveSymbol (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:26000:37)
    at StaticReflector.findSymbolDeclaration (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:25260:71)
    at StaticReflector.importUri (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:25235:54)
    at StaticAndDynamicReflectionCapabilities.importUri (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:25150:115)
    at Reflector.importUri (/Users/Documents/workspace/myapp/node_modules/@angular/core/bundles/core.umd.js:2189:94)
    at identifierModuleUrl (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:1993:26)
    at _TsEmitterVisitor._visitIdentifier (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:20359:46)
    at _TsEmitterVisitor.visitExternalExpr (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:20058:18)
    at ExternalExpr.visitExpression (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:14790:28)
    at /Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19856:64
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitAllObjects (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19872:17)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitAllExpressions (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19856:18)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitInvokeMethodExpr (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19604:18)
    at InvokeMethodExpr.visitExpression (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:14700:28)
    at /Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19856:64
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitAllObjects (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19872:17)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitAllExpressions (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19856:18)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitInstantiateExpr (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19663:18)
    at InstantiateExpr.visitExpression (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:14745:28)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitWritePropExpr (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19582:24)
    at WritePropExpr.visitExpression (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:14661:28)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitExpressionStmt (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19438:23)
    at ExpressionStatement.visitStatement (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:15156:28)
    at /Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19885:62
    at Array.forEach (native)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitAllStatements (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19885:24)
    at _TsEmitterVisitor.AbstractEmitterVisitor.visitIfStmt (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19479:22)
    at IfStmt.visitStatement (/Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:15301:28)
    at /Users/Documents/workspace/myapp/node_modules/@angular/compiler/bundles/compiler.umd.js:19885:62
    at Array.forEach (native)

Expected behavior

Checks for the undefined object or throws a more meaningful error message.

In its current form, I have no idea what is wrong....

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Easier debugging

Please tell us about your environment:

OS X
Angular Class Webpack AOT
NPM

  • Angular version: 2.0.X

Angular 2.4.9

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    TS 2.2.1
    "target": "es5",
    "module": "es2015",

  • Node (for AoT issues): node --version = Node 7.5.0

@DzmitryShylovich
Copy link
Contributor

Please add the github repo that reproduces the issue

@jt-helsinki
Copy link
Author

@DzmitryShylovich It's a private repo. I'm not allowed.

@DzmitryShylovich
Copy link
Contributor

We don't need your real code. Just a small demo. Otherwise we can't do anything.

@jt-helsinki
Copy link
Author

jt-helsinki commented Mar 15, 2017

@DzmitryShylovich can you please tell me what the StaticSymbolResolver does so I can narrow it down to something more meaningful? I don't know what to send.

Unfortunately, there has been some time between AOT compilations and there are quite a few changes....

@DzmitryShylovich
Copy link
Contributor

DzmitryShylovich commented Mar 15, 2017

@chuckjaz why can staticSymbol.members be undefined?

@chuckjaz
Copy link
Contributor

@DzmitryShylovich members should never be undefined in a static symbol. For some reason the compiler is getting a symbol that doesn't have a corresponding static symbol. The branch of code being executed by importUri should only be called during JIT not AOT and would only be executed when compilerIdentifer.reference is not a StaticSymbol which is always supposed to be.

@paistipoikka Unfortunately, the stack only tells me that there is a bug, not what is causing it. You can try adding a console.log(compilerIdentifier); in the compiler.umd.js in identifierModuleUrl to log whenever it calls the reflector's importUri method? That should, at least, give you an idea of what symbol is causing the issue.

@jt-helsinki
Copy link
Author

@DzmitryShylovich @chuckjaz Thanks guys, that worked.

It turned out that I was using the wrong provider key in one of my modules. I switched it out for an OpaqueToken and voila, problem solved.

For example, LOGGING_ERROR_HANDLER_OPTIONS here can not be used as a provider key:

export let LOGGING_ERROR_HANDLER_OPTIONS = {
    rethrowError: false,
    unwrapError: false
};


...


export const LOGGING_ERROR_HANDLER_PROVIDERS = [
    { provide: LOGGING_ERROR_HANDLER_OPTIONS, useValue: LOGGING_ERROR_HANDLER_OPTIONS },
    { provide: ErrorHandler, useClass: ErrorLoggingHandler }
];

this breaks.

Instead, set up an opaque token and use that.

Many thanks for your help.

JT

@DzmitryShylovich
Copy link
Contributor

DzmitryShylovich commented Mar 16, 2017

I got (angular 4)

Error: Internal error: unknown identifier {"reference":{"rethrowError":false,"unwrapError":false}}
    at _TsEmitterVisitor._resolveStaticSymbol (D:\Workspace\starter\node_modules\@angular\compiler\bundles\compiler.umd.js:12737:21)

@IgorMinar IgorMinar added area: core Issues related to the framework runtime type: bug/fix labels Mar 16, 2017
@tariknz
Copy link

tariknz commented Apr 19, 2017

I managed to replicate it when compiling with AOT.

Adding this in your module:
providers: { provide: Window, useValue: window },

Will error out:

ERROR in Internal error: unknown identifier {}

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' i
n 'X:\projects\graphy\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

The error message did not help at all, I digged it out with @chuckjaz suggestion to console.log(compilerIdentifier).

Thanks for the tip.

@chuckjaz chuckjaz self-assigned this Apr 20, 2017
@M-R-Bishop
Copy link

@paistipoikka What changes did you make exactly to convert this to an opaque token? I'm still trying to wrap my head around AoT and I'm running into the same error with Error Logging.

@jt-helsinki
Copy link
Author

@M-R-Bishop try the suggestion offered above by @chuckjaz

That should give the clues as to what has caused the error.

@dparish
Copy link

dparish commented Jun 27, 2017

Thank you very much for this thread. I'm on 4.2.4 and was getting a similar error:

ERROR in Internal error: unknown identifier undefined

This is a year old app that was started before AOT so we are having to unwind some bad practices. We had this in our App Module providers section:

    WindowService,
    {
      provide: Window,
      useValue: window
    }

I got rid of the bad provide and that fixed it.

@chuckjaz
Copy link
Contributor

@dparish Does this reproduce with 0.1.4? Adding this above code to an existing application and could not reproduce it.

@dparish
Copy link

dparish commented Jun 27, 2017

I tried it on 1.4.2 and 1.5.0-rc.1. Failed on both.

@chuckjaz
Copy link
Contributor

@dparish It is not that I don't believe you. I do. I just was unable to reproduce it. Can you put together a small example such as using ng new and making the modifications that would reproduce this.

@rdsedmundo
Copy link

@chuckjaz I can confirm that this still happens, using Angular 4.2.5 - not using the CLI, and making the AOT build from scratch.

Unfortunately, I can't provide you my code because it's a particular project. But I had the same provider registered ({ provide: Window, useValue: window }), which was done by another programmer and I didn't know. I accidentally have seen it and remembered about this issue here, because I saw yours discuss earlier today; and after removing the provider, it worked.

Here, the error was even weird, it said: Internal error: unknown identifier undefined.

@JoostK
Copy link
Member

JoostK commented Mar 15, 2020

This looks related to #15495 which is no longer an issue with Ivy, so closing as resolved.

@JoostK JoostK closed this as completed Mar 15, 2020
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime freq2: medium type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants