Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Get build passing for AOT example - #578

Merged
PatrickJS merged 4 commits into
angular:update-angular-2-0-1from
steve8708:update-angular-2-0-1
Oct 10, 2016
Merged

PatrickJS merged 4 commits into
angular:update-angular-2-0-1from
steve8708:update-angular-2-0-1

Conversation

@steve8708

@steve8708 steve8708 commented Oct 6, 2016 •

Copy link
Copy Markdown
Contributor

(this PR points to the update-angular-2-0-1 branch)

Comment thread modules/platform-node/node-platform.ts Outdated
import { HammerGesturesPlugin } from '@angular/platform-browser/src/dom/events/hammer_gestures';
import { DomRootRenderer } from '@angular/platform-browser/src/dom/dom_renderer';
import { SharedStylesHost, DomSharedStylesHost } from '@angular/platform-browser/src/dom/shared_styles_host';
import { DomSanitizerImpl } from '@angular/platform-browser/src/security/dom_sanitization_service';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexeagle we're running into this issue again 😞

One finding that seems relevant - in node-http.ts we export a function called __noop. When transpiled with ngc, ngc omits the function from the transpiled result. Renaming the function to _noop (i.e. one underscore prefix instead of two) the transpiled result preserves the exported function

There seems to be a strange handling in ngc of two underscore prefixed export names. It seems that this could be related

"stripInternal" is off throughout this project now (I even tried explicitly setting it to false in our tsconfig files and that didn't change anything), but we're still getting this problem

Would you happen to have any idea a way we can resolve this and get back to using private imports properly like we were?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stripInternal is only related to @internal, not to underscore prefix.
I don't know what "this issue" means, is there an issue filed?

@steve8708 steve8708 Oct 6, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the issue is when we import from __private_imports__ (which is a set of exports that are imported from private exports from angular, e.g. __platform_browser_private__ from @angular/platform-browser), when we compile with ngc the generated .d.ts file are missing type information for anything from those private exports

The code above replaces the commented code below, which we need to be using instead vs direct module path exports above

Before, your suggestion to set skipInternal to false fixed the @internal tags not being transpiled, but also fixed the __private_imports__ as well, so it seemed related

Now, for some reason though, we are seeing the issue again. And the __noop vs _noop example also showed the same result, i.e. if noop was prefixed with two underscores, it seems to be treated by ngc as being @internal, but removing one of the underscores leaves it treated as any other export again and emits properly

Let me know if I can clarify this better, it's certainly an odd issue that I've yet to fully wrap my head around so can be a little tough to describe well

@steve8708

steve8708 commented Oct 6, 2016 •

Copy link
Copy Markdown
Contributor Author

Also note that because this PR uses direct module paths the server won't run as the files at the full paths use ES modules which the server will throw on "unexpected token import" at runtime, so far us to be able to move on we need to resolve the issue of ngc not properly emitting .d.ts information for double underscore prefixed variables or find another workaround

@alexeagle

Copy link
Copy Markdown

What happens in @angular/platform-browser? It has the same imports from
other @angular packages, and compiles with metadata.json produced. Does it
have the same missing information in the output .d.ts files? Sorry, I think
I need a more minimal repro to follow exactly what's happening here. Is it
reproducible within the repo now, or do you still have to install universal
into an example app to see the problem?

On Thu, Oct 6, 2016 at 11:50 AM Steve Sewell notifications@github.com
wrote:

@steve8708 commented on this pull request.

In modules/platform-node/node-platform.ts
#578:

-import {

  • KeyEventsPlugin,
  • DomEventsPlugin,
  • HammerGesturesPlugin,
  • BROWSER_SANITIZATION_PROVIDERS,
  • DomRootRenderer,
  • SharedStylesHost,
  • DomSharedStylesHost,
    -} from './private_imports';
    +// Private imports - Remove me!
    +import { KeyEventsPlugin } from '@angular/platform-browser/src/dom/events/key_events';
    +import { DomEventsPlugin } from '@angular/platform-browser/src/dom/events/dom_events';
    +import { HammerGesturesPlugin } from '@angular/platform-browser/src/dom/events/hammer_gestures';
    +import { DomRootRenderer } from '@angular/platform-browser/src/dom/dom_renderer';
    +import { SharedStylesHost, DomSharedStylesHost } from '@angular/platform-browser/src/dom/shared_styles_host';
    +import { DomSanitizerImpl } from '@angular/platform-browser/src/security/dom_sanitization_service';

Sorry, the issue is when we import from private_imports (which is a
set of exports that are imported from private exports from angular, e.g.
platform_browser_private from @angular/platform-browser when we
compile with ngc the generated .d.ts file are missing type information for
anything from those private exports

Before, your suggestion to set skipInternal to false fixed the @internal
tags not being transpiled, but also fixed the private_imports as
well, so it seemed related

Now, for some reason though, we are seeing the issue again. And the __noop
vs _noop example also showed the same result, i.e. if noop was prefixed
with two underscores, it seems to be treated by ngc as being @internal,
but removing one of the underscores leaves it treated as any other export
again and emits properly

Let me know if I can clarify this better, it's certainly an odd issue that
I've yet to fully wrap my head around so can be a little tough to describe
well

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#578, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC5Iy8y7Ry51UM6--nO93m58THydw1Lks5qxUMIgaJpZM4KQRMa
.

@steve8708

steve8708 commented Oct 6, 2016 •

Copy link
Copy Markdown
Contributor Author

@alexeagle just made this branch to help easily reproduce the issues

It is the same as @gdi2290's branch but with the other build fixes so that as soon as the __private_imports__ work properly the full build should work end to end

to reproduce you'll want to

npm install 
gulp pre-publish
cd to examples/express-aot
npm run ngc && npm run build

You should see typescript complaining that everything from __private_imports__ is suddenly missing in the last step of the build

Interestingly, you will see that you will get the same issue if you, for example, rename _noop to __noop in node-http.ts, but naming it back to not have two underscores will allow it to be found again

Hope that helps, and thank you for your help!

@steve8708

steve8708 commented Oct 6, 2016 •

Copy link
Copy Markdown
Contributor Author

@alexeagle in case it helps, after a little more testing, it looks like with either ngc or tsc the .d.ts files that are created always seem to skip emitting metadata for anything with a double underscore prefix

So even when using tsc instead of ngc, our __private_imports__.d.ts file looks like this

export { BROWSER_SANITIZATION_PROVIDERS, SharedStylesHost, DomSharedStylesHost, DomRootRenderer, DomEventsPlugin, DomAdapter, setRootDomAdapter, KeyEventsPlugin, HammerGesturesPlugin, SelectorMatcher, CssSelector, ViewUtils, AnimationKeyframe, AnimationPlayer, AnimationStyles, RenderDebugInfo };
declare var __empty: any;
export default __empty;

Note it strips all of the imports of what is being exported (BROWSER_SANITIZATION_PROVIDERS, etc). Also note that in the original file those are being imported from a double underscore prefixed export (e.g. __platform_browser_private)

The original typescript file for __private_imports__.ts is

import { __platform_browser_private__ } from '@angular/platform-browser';
import { __core_private__ } from '@angular/core';
import { __compiler_private__ } from '@angular/compiler';

// PRIVATE
const {
  BROWSER_SANITIZATION_PROVIDERS,
  SharedStylesHost,
  DomSharedStylesHost,
  DomRootRenderer,
  DomEventsPlugin,
  KeyEventsPlugin,
  DomAdapter,
  setRootDomAdapter,
  HammerGesturesPlugin
} = __platform_browser_private__;

const {
  ViewUtils,
  AnimationKeyframe,
  AnimationPlayer,
  AnimationStyles,
  RenderDebugInfo
} = __core_private__;

const {
  SelectorMatcher,
  CssSelector
} = __compiler_private__;


// @internal
export {
  // platform-browser
  BROWSER_SANITIZATION_PROVIDERS,
  SharedStylesHost,
  DomSharedStylesHost,
  DomRootRenderer,
  DomEventsPlugin,
  DomAdapter,
  setRootDomAdapter,
  KeyEventsPlugin,
  HammerGesturesPlugin,

  // compiler
  SelectorMatcher,
  CssSelector,


  // core
  ViewUtils,
  AnimationKeyframe,
  AnimationPlayer,
  AnimationStyles,
  RenderDebugInfo,
}

var __empty = null;

export default __empty;

Perhaps it is just written into typescript to not emit exports or imports with a __ prefix, similar to @internal with stripInternal but maybe has it's own flag to turn off this behavior or has none at all. That or for some reason it seems to think that those imports are globally available (based on it's prefix?)

@steve8708

Copy link
Copy Markdown
Contributor Author

cc @gdi2290

@steve8708

Copy link
Copy Markdown
Contributor Author

@alexeagle @gdi2290 I pushed another commit here that works around the interfaces not found issue by using the private exports object directly without destructuring

Unfortunately, this causes this issue to happen. I believe this is a bug in the compiler CLI (if interested, see comments on issue for detail). I've run into it before and always use the same workaround

Manually updating the angular/compiler-cli code (gross, I know) with the sample I note in the github issue allows the build to work end to end. Even if we don't want to use these updates as-is, at least hopefully this information is useful by demonstrating a workaround to the .d.ts issue that does in fact work

@steve8708
steve8708 force-pushed the update-angular-2-0-1 branch from ac7ff31 to 8b49354 Compare October 7, 2016 00:15
@steve8708
steve8708 force-pushed the update-angular-2-0-1 branch from 85fead2 to f932975 Compare October 7, 2016 18:50
@steve8708

Copy link
Copy Markdown
Contributor Author

@gdi2290 FYI this completely works now once this in angular/angular gets merged

@steve8708

steve8708 commented Oct 7, 2016 •

Copy link
Copy Markdown
Contributor Author

(also note the reason the build fails is for the same issue my PR to angular/angular resolves, so once that is merged and published this should pass build and be unblocked)

I've also manually verified through linking that with my updates to angular the build passes as expected

@PatrickJS
PatrickJS merged commit 3d7c56d into angular:update-angular-2-0-1 Oct 10, 2016
@PatrickJS

Copy link
Copy Markdown
Contributor

@steve8708 thanks, merged to my PR

@steve8708

steve8708 commented Oct 10, 2016 •

Copy link
Copy Markdown
Contributor Author

@gdi2290 👍

note there is one more issue I've found. If you manually updated node_modules/@angular/compiler with a similar change as my PR to allow the build will pass but you'll get runtime errors that providers cannot be found (e.g. DomRootRenderer)

Taking a look at that now but it is a strange one that is a little tricky to try and poke into why exactly that happens only in AOT mode and not in JIT mode

@alexeagle

Copy link
Copy Markdown

I had similar problem with providers not found. The issue was the ngfactory
needs to determine if two static symbols are the same: the one imported and
the one used in the constructor of the component being compiled. If these
are accidentally not the same, the generated code will try to ask the
parent injector for the dependency instead.
It may be that your fix for the isStaticSymbol is the wrong fix...

On Mon, Oct 10, 2016 at 12:09 PM Steve Sewell notifications@github.com
wrote:

@gdi2290 https://github.com/gdi2290 👍

note there is one more issue I've found. If you manually updated
node_modules/@angular/compiler with a similar change as my PR to angular
the build will pass but you'll get runtime errors that providers cannot be
found (e.g. DomRootRenderer)

Taking a look at that now but it is a strange one that is a little tricky
to try and poke into why exactly that happens only in AOT mode and not in
JIT mode

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#578 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC5IxUAt8l1tZwZuQ097KudIp5FpZ-wks5qyo1kgaJpZM4KQRMa
.

@steve8708

Copy link
Copy Markdown
Contributor Author

Ah... this is very helpful, thank you @alexeagle! I'll dig in deeper and see if I can verify. Poking around the compiled ngfactory code could possibly help, will try that first

@StefanRein

StefanRein commented Feb 21, 2017 •

Copy link
Copy Markdown

Maybe it's not direct related to this issue, but since I got here:
I had a missing dependency in a generated *.ngfatory for the constructor. With JIT it worked fine, with AOT not. Error was: I forgot the @Injectable() above the service class. Did put it there and it worked again.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 5, 2019
@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants