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

import as results in the alias being undefined with Typescript 3.2 #13212

Closed
IgorMinar opened this issue Dec 18, 2018 · 7 comments · Fixed by #13226
Closed

import as results in the alias being undefined with Typescript 3.2 #13212

IgorMinar opened this issue Dec 18, 2018 · 7 comments · Fixed by #13226

Comments

@IgorMinar
Copy link
Contributor

IgorMinar commented Dec 18, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting

Command (mark with an x)

- [x] serve
- [x] e2e

Versions

Angular CLI: 7.1.3
Node: 10.11.0
OS: darwin x64
Angular: 7.2.0-beta.2+55.sha-a6e6763
... animations, common, compiler, compiler-cli, core, elements
... forms, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.7
@angular-devkit/build-angular     0.10.7
@angular-devkit/build-optimizer   0.10.7
@angular-devkit/build-webpack     0.10.7
@angular-devkit/core              7.1.3
@angular-devkit/schematics        7.1.3
@angular/cdk                      7.0.0
@angular/cli                      7.1.3
@angular/material                 7.0.0
@ngtools/webpack                  7.0.7
@schematics/angular               7.1.3
@schematics/update                0.11.3
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.19.1

Repro steps

After typescript 3.2 upgrade, I've started seeing e2e test failures due to certain symbols not being defined - in all cases these symbols came from rxjs and were aliased to a different name.

The problem occurs during dev builds without optimizations turned on and causes both ng serve and ng e2e to fail with runtime errors in the browser

For example:

import { from as fromPromise, Observable } from 'rxjs';

Would end up with fromPromise being undefined at runtime.

Workarounds

  • remove the as alias and refactor the code to use the original symbol name.
  • revert back to typescript 3.1

More info

I'll try to create a minimal reproduction outside of aio but for now you can review the "workaround" commit in https://github.com/angular/angular/pull/27536/commits

In the meantime I've tested the as imports in vanilla tsc and it seems to be working just fine there, so I suspect that it's some kind of interaction with cli or webpack that is causing this.

IgorMinar added a commit to IgorMinar/angular that referenced this issue Dec 18, 2018
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212
@IgorMinar
Copy link
Contributor Author

hmm.. unfortunately I can't seem to be able to reproduce this outside of angular.io... in aio it's quite easy to repro this, but I don't know what makes aio special.

IgorMinar added a commit to IgorMinar/angular that referenced this issue Dec 18, 2018
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212
@thw0rted
Copy link

I have spent all day tearing my hair out trying to nail this down... I'm glad to see I'm not alone. I also haven't been able to make a lightweight reproduction yet -- I have a lot of moving pieces in my (broken) build and thought it might have been some interaction between webpack, the DLL/DLLReference plugins, and the AOT compiler. I just finally figured out that it must be something to do with @ngtools/webpack because I couldn't get the error to happen without it.

I'm going to spend a little more time trying to make a compact reproduction but if it's impossible to build core Angular as-is under TS 3.2, that's probably good enough to make sure it gets addressed. I just hope we don't spend too long with "workarounds" like taking out aliasing completely. I don't just use those as a nice-to-have, I have a dependency where they export a variable I need called "Math"... and I need to access the actual Math object in the same place. As far as I can tell I don't really have any recourse other than aliasing (or renaming the global Math somewhere, which is definitely worse).

@thw0rted
Copy link

Just noticed that this corresponds with a change in import-alias behavior in a recent VSCode version, and I'm wondering if there's some connection? See e.g. this issue.

@alan-agius4
Copy link
Collaborator

I had a quick look at this, and it seems that this is only happening in AOT mode.

AIO is "special" because it's serve uses AOT and buildOptimizer. Running node_modules/.bin/ngc -p src/tsconfig.app.json in the AIO folder, does output the correct import as statements.

mhevery pushed a commit to angular/angular that referenced this issue Dec 18, 2018
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212

PR Close #27536
IgorMinar added a commit to IgorMinar/angular that referenced this issue Dec 19, 2018
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212

PR Close angular#27536
IgorMinar added a commit to IgorMinar/angular that referenced this issue Dec 19, 2018
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212

PR Close angular#27536
mgechev pushed a commit that referenced this issue Dec 19, 2018
…ed with Typescript 3.2

When using the `specifier.propertyName` with `typeChecker.getSymbolAtLocation` it will return a more detailed symbol then we originally have in the `usedSymbols` set.

We should probably use `symbol.id` to actually check if the symbols are the same, however the `id` is not exposed in the Symbol interface.

Using `node.name` will return the same symbol that we have stored in the set.

Fixes #13212
@thw0rted
Copy link

Does this issue automatically get notified when the patch is included in a published release? If not, do we have an ETA on when this might land?

hansl pushed a commit that referenced this issue Dec 20, 2018
This also adds the option to provide addition files when using `createTypescriptContext` this is paramount for the elide imports tests as without this certain symbols won't have the full details.

Which will cause tests to be false positive and re-surface issues like #13212
alexeagle pushed a commit that referenced this issue Jan 15, 2019
This also adds the option to provide addition files when using `createTypescriptContext` this is paramount for the elide imports tests as without this certain symbols won't have the full details.

Which will cause tests to be false positive and re-surface issues like #13212
@IgorMinar
Copy link
Contributor Author

IgorMinar commented Jan 27, 2019 via email

ngfelixl pushed a commit to ngfelixl/angular that referenced this issue Jan 28, 2019
It's unclear why `import as` results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it
might be some kind of interaction in @angular/cli or webpack that are
causing the failure.

This should be investigated separately from the tsc update in
angular/angular. See angular/angular-cli#13212

PR Close angular#27536
@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 9, 2019
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
…ed with Typescript 3.2

When using the `specifier.propertyName` with `typeChecker.getSymbolAtLocation` it will return a more detailed symbol then we originally have in the `usedSymbols` set.

We should probably use `symbol.id` to actually check if the symbols are the same, however the `id` is not exposed in the Symbol interface.

Using `node.name` will return the same symbol that we have stored in the set.

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

Successfully merging a pull request may close this issue.

3 participants