Angular-cli: Error while using typescript 3.8 export aliases

Created on 14 Mar 2020  路  8Comments  路  Source: angular/angular-cli

馃悶 bug report

Description

Using typescript 3.8 export aliases produces an error while building.
Happens with ivy enabled as well as disabled.

馃敩 Minimal Reproduction

  1. Clone the error repo https://github.com/TomTomB/named-exports-issue
  2. Run npm i
  3. Run ng serve
  4. Look inside the terminal output

馃敟 Exception or Error

ERROR in ./src/app/stuff/index.ts 1:9
Module parse failed: Unexpected token (1:9)
File was processed with these loaders:
 * ./node_modules/@ngtools/webpack/src/index.js
You may need an additional loader to handle the result of these loaders.
> export * as fromFoo from './foo';

馃實 Your Environment

Angular CLI: 9.1.0-next.3
Node: 12.13.0
OS: win32 x64

Angular: 9.1.0-next.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.901.0-next.3
@angular-devkit/build-angular 0.901.0-next.3
@angular-devkit/build-optimizer 0.901.0-next.3
@angular-devkit/build-webpack 0.901.0-next.3
@angular-devkit/core 9.1.0-next.3
@angular-devkit/schematics 9.1.0-next.3
@angular/cli 9.1.0-next.3
@ngtools/webpack 9.1.0-next.3
@schematics/angular 9.1.0-next.3
@schematics/update 0.901.0-next.3
rxjs 6.5.4
typescript 3.8.3
webpack 4.42.0

blocked on upstream devkibuild-angular low broken triage #1 bufix

Most helpful comment

Setting the "module" flag to "es2015" only works, if lazy loading is not used.

```
Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.

12 loadChildren: () => import('./features/foo/foo.module').then((m) => m.FooModule)
```

All 8 comments

In your project, the "module" compiler flag in tsconfig.json is configured as "esnext". This means that the export is preserved as is, however some part of the toolchain is unable to process that syntax. If you change "module" to "es2015" instead it will work.

Looks like it's Webpack itself that has to support this syntax so that it can work its magic: https://github.com/webpack/webpack/issues/10460

Setting the "module" flag to "es2015" only works, if lazy loading is not used.

```
Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.

12 loadChildren: () => import('./features/foo/foo.module').then((m) => m.FooModule)
```

Is there a workaround for this?

Habing same issue as author, setting the module flag as "ES2015" will fix it if not using lazy loading, which does break with this change :/ Subscribing to this issue to know when it is fixed.

Any news yet on this?

This should be fixed in Webpack 5 (https://github.com/webpack/webpack/pull/11117), which is currently in opt-in preview in Angular CLI 11.

See #18820 for more information on how to opt-in Webpack 5.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

purushottamjha picture purushottamjha  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

hartjo picture hartjo  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments