Skip to content

production build failed "Module parse failed" with "export default class" syntax #14769

@kawamoto

Description

@kawamoto

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

build-optimizer: 0.800.1 works fine.

Description

A clear and concise description of the problem...

It seems #14585 breaks below syntax

export default class Foo { .. }

after this change, it converts that code to

export default const Foo = { .. }

export default const is not valid syntax. ng build --prod failed with above code in parsing by acorn cause of that syntax.

🔬 Minimal Reproduction

execute ng build --prod with this project
https://github.com/kawamoto/ng-export-default-class

🔥 Exception or Error





ERROR in ./src/app/foo.js 1:15
Module parse failed: Unexpected token (1:15)
You may need an appropriate loader to handle this file type.
> export default const Foo = /*@__PURE__*/ (() => {
|     class Foo {
|         constructor() {

🌍 Your Environment





Angular CLI: 8.0.2
Node: 11.3.0
OS: darwin x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.2
@angular-devkit/build-angular     0.800.2
@angular-devkit/build-optimizer   0.800.2
@angular-devkit/build-webpack     0.800.2
@angular-devkit/core              8.0.2
@angular-devkit/schematics        8.0.2
@angular/cli                      8.0.2
@ngtools/webpack                  8.0.2
@schematics/angular               8.0.2
@schematics/update                0.800.2
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions