0

I've got an angular 2 component that when I put in app-name/src/app/component-folder/component.ts and import like import {Component} from './component-folder/component' works just fine.

But when the component is installed to the app-name/node_modules folder at app-name/node_modules/component-folder/component and I do

import {Component} from 'component-folder/component'

or import {Component} from '../../node_modules/component-folder/component'

It gives me this error: Unexpected value 'Component' declared by the module 'AppModule'

Why is that and how do I fix it?

Supamiu
  • 8,501
  • 7
  • 42
  • 76
Joshua Terrill
  • 1,995
  • 5
  • 21
  • 40
  • What is "it"? tsc or angular2 runtime? Also, please add systemjs.config.js file. – Supamiu Sep 29 '16 at 09:17
  • I had the reverse issue (using pure js not ts)! I couldn't get an npm module to load properly, but inspired by your post here I tried copying the module local to the same directory as the file I was importing it into and it worked! http://stackoverflow.com/questions/39759764/unexpected-value-fileuploadmodule-imported-by-the-module-uploadermodule-ng – crowmagnumb Sep 30 '16 at 00:25

1 Answers1

0

Because module resolution by tsc is different when it looks for something from node_modules. https://www.typescriptlang.org/docs/handbook/module-resolution.html

lbrahim
  • 3,710
  • 12
  • 57
  • 95
  • I still don't understand how I would make it so I can import my component from the node modules. I've read a couple things about changing the `module: "commonjs"` in tsconfig, and then use `module: module.id` in the `@Component` declaration. But nothing is working yet. – Joshua Terrill Sep 30 '16 at 03:12