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

exported default function might break AOT #17518

Closed
8 tasks
schmitch opened this issue Jun 14, 2017 · 5 comments · Fixed by #17642
Closed
8 tasks

exported default function might break AOT #17518

schmitch opened this issue Jun 14, 2017 · 5 comments · Fixed by #17642
Assignees
Labels
area: core Issues related to the framework runtime type: bug/fix

Comments

@schmitch
Copy link

schmitch commented Jun 14, 2017

I'm submitting a ...


[ ] Regression (behavior that used to work and stopped working in a new release)
[X] Bug report 
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Below code fails with:

ERROR in Cannot read property 'text' of undefined

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'HOME/demo-app/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

Expected behavior

That code:

export default function () {

  const mainRoutes = [
    {name: 'a', abstract: true, component: 'main'},

    {name: 'a.welcome', url: '/welcome', component: 'welcome'}
  ];

  return mainRoutes;

}

should compile fine under AOT. it's actually a simple array. removing the unncessary variable, should work, too.

Minimal reproduction of the problem with instructions

Create a file called states.ts somewhere in your source folder (does not need to be imported) and insert the code above.
Run ng build --prod.

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

Please tell us about your environment

Angular version: 4.2.2

Browser:

  • Chrome (desktop) version XX
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

For Tooling issues:

  • Node version: v8.1.1
  • Platform: Mac OS X 11.11

Others:
Might be related, but different error message: #11402
Looks like that works:

export default [
    {name: 'a', abstract: true, component: 'main'},

    {name: 'a.welcome', url: '/welcome', component: 'welcome'}
];

which however is also default

@schmitch schmitch changed the title Simple Exported Function breaks AOT exported default function might break AOT Jun 14, 2017
@hansl
Copy link
Contributor

hansl commented Jun 15, 2017

This issue seems to be a CLI issue. Please file it at http://github.com/angular/angular-cli/issues/new. This repo is for the Angular framework itself. Thanks!

@hansl hansl closed this as completed Jun 15, 2017
@schmitch
Copy link
Author

@hansl how can this be a cli error?

this is the full output when running ngc:

schmitch:~/projects/envisia/erp/loki/ui$ ./node_modules/.bin/ngc 
TypeError: Cannot read property 'text' of undefined
    at exportedIdentifierName (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/tsc-wrapped/src/collector.js:242:44)
    at exportedName (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/tsc-wrapped/src/collector.js:244:53)
    at /Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/tsc-wrapped/src/collector.js:343:38
    at visitEachNode (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/typescript/lib/typescript.js:14785:30)
    at Object.forEachChild (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/typescript/lib/typescript.js:14959:24)
    at MetadataCollector.getMetadata (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/tsc-wrapped/src/collector.js:280:12)
    at CompilerHost.getMetadataFor (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/compiler-cli/src/compiler_host.js:199:51)
    at StaticSymbolResolver.getModuleMetadata (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:25453:62)
    at StaticSymbolResolver._createSymbolsOf (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:25259:46)
    at StaticSymbolResolver.getSymbolsOf (/Users/schmitch/projects/envisia/erp/loki/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:25240:14)
Compilation failed

I tought the compiler lies in this repo...

@chuckjaz
Copy link
Contributor

The referenced PR will fix the crash but will but this code will still not be supported.

First, we don't support referencing default functions in AOT metadata. We are working on this but his will not be resolved until sometime after 5.0.

Second, the function is not a simple function that we require. I have a document that describes the limitations on TypeScript syntax we support in metadata here https://gist.github.com/chuckjaz/65dcc2fd5f4f5463e492ed0cb93bca60. We are also lifting many of these restrictions for 5.0 but the simple (or macro) function limitation will still be there for 5.0.

Changing this to

export function mainRoutes() {
  return [
    {name: 'a', abstract: true, component: 'main'},
    {name: 'a.welcome', url: '/welcome', component: 'welcome'}
  ];
}

and then importing {mainRoutes} will work.

We must be able to determine the value of the routes at compile time and we cannot support all the features of JavaScript and TypeScript during this evaluation. We are continually improving this and have significant improvements coming.

@schmitch
Copy link
Author

well I think no matter if supported or not. having at least a sane error message would help ;)

@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 Sep 11, 2019
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 type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants