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

Typescript enum + namespace declaration merging causes error #680

Closed
dallastjames opened this issue Mar 9, 2018 · 6 comments
Closed

Typescript enum + namespace declaration merging causes error #680

dallastjames opened this issue Mar 9, 2018 · 6 comments

Comments

@dallastjames
Copy link

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

When trying to package a library that has an exported enum that is merged with a namespace, the build throws the error Identifier '{enumName}' has already been declared. I use this format in several different Angular projects and there are no issues when running something like this through the ngc compiler (both JIT and AOT work correctly). Seems to be something possibly related to how the packaging works with rollup. From what I can tell, rollup doesn't deal with typescript so I figured I'd start here and hopefully find a solution.

How To Reproduce

https://plnkr.co/edit/ofKm8uDao8IxQlFb0rj4

Using the files provided in the plunker (standard ng-packagr setup with a single enum file):
npm i
npm run build

Building Angular Package
Building entry point 'packagr-enum-bug'
Cleaning build directory
Rendering Stylesheets
Rendering Templates
Compiling TypeScript sources through ngc
Bundling to FESM15

BUILD ERROR
Identifier 'Color' has already been declared (15:11) in C:\...\packagr-bug\.ng_pkg_build\packagr-enum-bug\out\my-enum.js
SyntaxError: Identifier 'Color' has already been declared (15:11) in C:\...\packagr-bug\.ng_pkg_build\packagr-enum-bug\out\my-enum.js
    at error (C:\...\packagr-bug\node_modules\rollup\dist\rollup.js:170:15)
    at C:\...\packagr-bug\node_modules\rollup\dist\rollup.js:17548:17
    at <anonymous>

Expected Behaviour

Build should complete successfully.

Version Information

ng-packagr: 2.2.0
@angular/*: ^5.2.0
typescript: 2.6.2
node: 8.9.3
npm: 5.5.1
@willemsendennis
Copy link

I use the following workaround:
Don't export the enum and namespace, but export Color at the end.
I think the result is the same (please correct me if it isn't) and I haven't noticed any unwanted side effects.

enum Color {
    red = 1,
    green = 2,
    blue = 4
}

namespace Color {
    export function mixColor(colorName: string) {
        if (colorName == "yellow") {
            return Color.red + Color.green;
        }
        else if (colorName == "white") {
            return Color.red + Color.green + Color.blue;
        }
        else if (colorName == "magenta") {
            return Color.red + Color.blue;
        }
        else if (colorName == "cyan") {
            return Color.green + Color.blue;
        }
    }
}

export {Color};

@jfrankowski
Copy link

jfrankowski commented Jul 12, 2018

Workaround does not work for me with

"devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-ng-packagr": "~0.6.8",
    "@angular-devkit/build-angular": "~0.6.8",
    "ng-packagr": "3.0.3",
    "tsickle": ">=0.25.5",
    "tslib": "^1.7.1",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }

@jforjava1981
Copy link

Any updates on this ? I am facing the same issue with following versions

  1. ng packagr: 4.4.5
  2. compiler-cli: ^6.1.1
  3. angular/cli:^6.1.2
    4)angular-devkit/build-angular:~0.6.1
    5)devkit-build/ng-pacakgr:~0.6.8

Will be really a help if anybody cofirms what the issue is.

@jforjava1981
Copy link

jforjava1981 commented Dec 12, 2018

ok it actually doesnt work with @willemsendennis solution

@alan-agius4
Copy link
Member

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent version.

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
@github-actions
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.

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants