0

I have to import a javascript file in my app module

import { OtherComponent } from './node_modules/blahblah/OtherComponent.js'

Notice that this OtherComponent is a javascript file already.

Then inside my @NgModule, I added this component to my declaration.

When I run "ng build --prod", it gives me error:

ERROR Unexpected value 'OtherComponent' declared by the module 'AppModule'

Please add a @Pipe/@Directive/@Component annotation

Is there a way to fix this? when I don't have access to the ts file of OtherComponent.

Community
  • 1
  • 1
bgail123
  • 11
  • 1

1 Answers1

0

You should not import JS files like this.

Inside the angular-cli.json file.

"scripts": [ "./node_modules/blahblah/OtherComponent.js" ];

Then restart your project. This should do the job.

  • ok. This OtherComponent has to declared in the appmodule though, so that I can use it throughout my app. Is that possible? – bgail123 Aug 22 '18 at 04:59
  • Ok. for that, add this in typings.d.ts declare var OtherComponent:any; Import it in your file as import * as otherComponent from 'OtherComponent'; – Vishal Singh Aug 22 '18 at 05:03
  • still no luck. When I import * as otherComponent from 'OtherComponent', 'OtherComponent' is not recognized – bgail123 Aug 22 '18 at 06:41