Skip to content

Aliased imports from a barrel file only work in development #7066

Closed

Description

@jak

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.1.2
node: 6.10.1
os: darwin x64
@angular/common: 4.2.3
@angular/compiler: 4.2.3
@angular/core: 4.2.3
@angular/forms: 4.2.3
@angular/http: 4.2.3
@angular/platform-browser: 4.2.3
@angular/platform-browser-dynamic: 4.2.3
@angular/router: 4.2.3
@angular/cli: 1.1.2
@angular/compiler-cli: 4.2.3

macOS Sierra

Repro steps.

Given an example file example/foo.ts

export function foo(): number { 
  return 1;
}

Given an example/index.ts file such as

export * from 'foo.ts';

When you have an aliased import such as

import { foo as exampleFoo } from './example';

The import works fine in development with ng serve, however whilst ng build --prod --aot succeeds, the resulting code does not run due to an error TypeError: Cannot read property 'apply' of undefined

If you change the import to not use the barrel file, the resulting compiled code is fine. i.e.

import { foo as exampleFoo } from './example/foo';

The log given by the failure.

When viewing the dist code:
TypeError: Cannot read property 'apply' of undefined

No errors during ng build.
No errors when using ng serve.

Desired functionality.

Consistency between development and production builds for imports.

Mention any other details that might be useful.

Activity

  1. clydin commented on Jul 20, 2017

    @clydin
    Member

    Can you try with Angular 4.3? The AOT compiler received some major updates and may resolve your issue.

    Also, a production build automatically includes AOT. You don't need to add the "--aot" option.

  2. removed their assignment
    on Feb 6, 2018
  3. rubenmarcus commented on Mar 21, 2018

    @rubenmarcus

    still doesnt work in Angular 5.2.0

  4. rubenmarcus commented on Mar 21, 2018

    @rubenmarcus

    main.b771427faeac57797e03.bundle.js:1 Uncaught TypeError: Cannot read property '__extends' of undefined
    at main.b771427faeac57797e03.bundle.js:1
    at Object.x35b (main.b771427faeac57797e03.bundle.js:1)
    at o (inline.c7e7d2e66b46b1ee9e69.bundle.js:1)
    at Object.0 (main.b771427faeac57797e03.bundle.js:1)
    at o (inline.c7e7d2e66b46b1ee9e69.bundle.js:1)
    at window.webpackJsonp (inline.c7e7d2e66b46b1ee9e69.bundle.js:1)
    at main.b771427faeac57797e03.bundle.js:1

    code:

    export * from './authenticator/company.model';
    export * from './authenticator/user.model';
    export * from './authenticator/person.model';
    

    import { Company , Person, User } from '@vamos-webapp/models';

    not working in ng serve --prod

  5. jacobbullock commented on May 4, 2018

    @jacobbullock

    Is this getting any attention? We are experiencing this in 5.2 as well

  6. gnovotny commented on Jun 7, 2018

    @gnovotny

    Experiencing this as well in version 6

    Problem goes away when you build with --build-optimizer=false

  7. alan-agius4 commented on Oct 10, 2018

    @alan-agius4
    Collaborator

    I'm sorry, but we can't reproduce the problem following the instructions you provided.
    Remember that we have a large number of issues to resolve, and have only a limited amount of time to reproduce your issue.
    Short, explicit instructions make it much more likely we'll be able to reproduce the problem so we can fix it.

    If the problem persists, please open a new issue following our submission guidelines.

    A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

  8. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Impacts a large percentage of users; if a workaround exists it is partial or overly painfulneeds: investigationRequires some digging to determine if action is neededseverity3: brokentype: bug/fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions