Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Cannot read property 'text' of undefined #109

Closed
lukashlobil opened this issue Apr 4, 2017 · 7 comments
Closed

Cannot read property 'text' of undefined #109

lukashlobil opened this issue Apr 4, 2017 · 7 comments

Comments

@lukashlobil
Copy link

lukashlobil commented Apr 4, 2017

I am not really sure, where the problem is, I am getting:

Cannot read property 'text' of undefined .
I am posting this issue here, because it seems related to this, which is angular cli's implementation of webpack.

ERROR in ...myClass.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (node_modules/typescript/lib/typescript.js:6641:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (node_modules/typescript/lib/typescript.js:78689:23)
    at IdentifierObject.TokenOrIdentifierObject.getText /node_modules/typescript/lib/typescript.js:78710:77)
    at refactor.findAstNodes.filter /node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./app.module.ts 4:17-58
 @ ./main.ts

myClass is a simple angular service

@Injectable()
export class MyClass<T> {

	constructor(private api: Api, private path: string, private includeAppId: boolean = true, private byParam: string = '') {}

	findAll(): Observable<T[]> {
		return this.api.buildRequest<T[]>(this.path, RequestMethod.Get, this.includeAppId);
	}

'text' property is not mentioned anywhere in the class.

My app.module:

export function apiLink(api: Api) {
	return new MyClass(api, 'path');
}
---------------------------------------------------------------------------------
{provide: API_LINK, useFactory: apiLink, deps: [Api]},

injecting the service somewhere in the app:
injector.get(API_LINK);

Looking for any kind of help / pointers. thanks

@sis0k0
Copy link
Contributor

sis0k0 commented Apr 17, 2017

Hey @lukashlobil,

Can you post your package.json and especially the version of @ngtools/webpack that you are using. The issue is clearly comes from that plugin as you can see from the error log.

@lukashlobil
Copy link
Author

Hello @sis0k0 thank you, package is posted in this gist: https://gist.github.com/lukashlobil/e7e81852cdc9e746fa7e79ac03cc6545

@sis0k0
Copy link
Contributor

sis0k0 commented Apr 20, 2017

Hi @lukashlobil,

I've been trying to reproduce this in a simple app, but I couldn't get the same error. Can you send a really simple sample project with the error, so I can debug it. Thank you in advance!

@DanielKucal
Copy link

@sis0k0, I've prepared a reproduce of this error using symlink and sample-Groceries project: https://github.com/DanielKucal/sample-Groceries/tree/cannot-read-text-of-undefined-repro
That's probably just one of possible reasons, I'd like to see more detailed errors in Nativescript.

@lukashlobil
Copy link
Author

@DanielKucal I have used a symlink as well (like angular-advanced-seed). Had to get rid of it and now I don't get this error as well. This service myClass was symlinked. Well, I guess, don't use symlinks.

@DanielKucal
Copy link

Hi @lukashlobil, I really need symlinks as AoT compilation hasn't been used for my Angular project so its code is incompatible. That's why I've developed a simple tool for replacing symlinks by real files to make a build and revert them afterwards. If you think you will need them anyway, then take a look at symlink-resolver. Good luck

@lukashlobil
Copy link
Author

I moved the symlinked files to its own repo, but thank you, this will come in handy

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants