Rahul Salvi
Rahul Salvi

Reputation: 364

SVG component in Angular library project gives 'Unknown word' error

I am creating a npm library package in Angular 8.1.3

If I add an SVG file as a component template in the library project then the build command ng build <project-name> gives my-comp.component.svg:1:1: Unknown word error.

However if I add an SVG file as a component template in the main app, then it builds successfully. Please help.

Angular CLI: 8.1.2
Node: 12.3.1
OS: win32 x64
Angular: 8.1.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.801.2
@angular-devkit/build-angular      0.801.2
@angular-devkit/build-ng-packagr   0.801.2
@angular-devkit/build-optimizer    0.801.2
@angular-devkit/build-webpack      0.801.2
@angular-devkit/core               8.1.2
@angular-devkit/schematics         8.1.2
@angular/cli                       8.1.2
@ngtools/json-schema               1.1.0
@ngtools/webpack                   8.1.2
@schematics/angular                8.1.2
@schematics/update                 0.801.2
ng-packagr                         5.3.0
rxjs                               6.5.2
typescript                         3.4.5
webpack                            4.35.2

Upvotes: 1

Views: 1295

Answers (2)

Rahul Salvi
Rahul Salvi

Reputation: 364

I was able to fix this using below steps:

  1. Update Angular CLI to latest version using

    npm install @angular/cli

  2. Update ng-packagr using

    npm i ng-packagr@latest

  3. Import BrowserModule in the root module of library project

    import { BrowserModule } from '@angular/platform-browser';

    ...

    @NgModule({ imports: [ BrowserModule ]

  4. Then build the project using ng build my-project command

Upvotes: 0

Will
Will

Reputation: 410

I submitted a bug, looks like it got PRed in, just have to wait till it gets released. https://github.com/angular/angular-cli/issues/15187.

I inlined my svg, and I think it worked, you could try that in the meantime.

Upvotes: 1

Related Questions