问题描述
我有一个角度2组件,当我放入 app-name/src/app/component-folder/component.ts
并从正常工作.
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.
但是当组件安装到 app-name/node_modules/component-folder/component
的 app-name/node_modules
文件夹中时,我会这样做
But when the component is installed to the app-name/node_modules
folder at app-name/node_modules/component-folder/component
and I do
从'component-folder/component'
或从'../../node_modules/component-folder/component'
它给了我这个错误:模块'AppModule'声明了意外的值'Component'
为什么会这样,我该如何解决?
Why is that and how do I fix it?
推荐答案
因为从tsc查找 node_modules
中的内容时,tsc的模块分辨率不同. https://www.typescriptlang.org/docs/handbook/module-resolution.html
Because module resolution by tsc is different when it looks for something from node_modules
. https://www.typescriptlang.org/docs/handbook/module-resolution.html
这篇关于导入组件在app文件夹中有效,但通过npm作为node_module安装时无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!