Maihan Nijat
Maihan Nijat

Reputation: 9344

ng build --prod throws Unexpected token: punc ()) because of imported library in the module list

The app loads fine with ng serve but throws Unexpected token: punc ()) while building with ng build --prod. Build the app with source map and found the reason which is caused by angular-gauge-chart. Asked the library developers for help and this is what they said:

@maihannijat it is a library, not an angular app. We use ng serve command to run an app that hosts a dev environment for the library. The library can be built using usual ng build angular-gauge-chart command.

I imported the module:

@NgModule({
  declarations: [XYZ],
  imports: [
    ...
    GaugeChartModule,
  ]
})

And used in the component template:

<rg-gauge-chart [canvasWidth]="canvasWidth"
                [needleValue]="needleValue"
                [centralLabel]="centralLabel"
                [options]="options"
                [name]="name"
                [bottomLabel]="bottomLabel">
</rg-gauge-chart>

I did exactly their guide says here: https://github.com/recogizer/angular-gauge-chart

I tried to import library in the component as:

import 'angular-gauge-chart';

And removed from the modules but it throws binding errors and asks for GaugeChartModule to be imorted in the modules.

Edit:

Debug with:

ng build --prod --named-chunks --verbose --build-optimizer=false --source-map

Error:

Unexpected token: punc ()) [./node_modules/gauge-chart/dist/bundle.js:169,0]

.attr(
  'transform',
  'translate(' + (n + 2 * e) + ', ' + (n + e) + ')',
)

Upvotes: 2

Views: 1650

Answers (3)

user2991036
user2991036

Reputation: 421

That's fixed in [email protected]. Thank you again for pointing this out.

For those who will ever face the same problem, this answer helped me to find the problem. In my case, the problem was in one of dependencies that didn't have proper bundle.js file. My prettier was configured in such way that it formatted already built bundle. Thus, some commas and other important information was lost.

Upvotes: 2

Maihan Nijat
Maihan Nijat

Reputation: 9344

The version 0.7.1 throws error because of trailing commas. I am using version 0.6.0 now until the developers fix the problem in the new version.

Reference: https://github.com/recogizer/angular-gauge-chart/issues/28

Upvotes: 1

import * as angularGaugeChart from 'angular-gauge-chart';

Upvotes: -1

Related Questions