angular 2 + npm 安装包不起作用 [英] angular 2 + npm install package not working
本文介绍了angular 2 + npm 安装包不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我通过 npm install
安装新包时,我的 angular 2 导入都无法识别该包,并且我的浏览器返回 404 错误
.
Whenever I install a new package via npm install
my angular 2 import is not recognizing the package and my browser returns 404 error
.
例如,我一直在尝试安装以下软件包:
For example, I've been trying to install the following package:
https://github.com/dougludlow/ng2-bs3-modal
这是我的浏览器返回的内容:
and this is what my browser returns:
GET http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal 404 (Not Found)fetchTextFromURL @ system.src.js:1154(anonymous function) @ system.src.js:1710ZoneAwarePromise @ angular2-polyfills.js:589(anonymous function) @ system.src.js:1709(anonymous function) @ system.src.js:2734(anonymous function) @ system.src.js:3308(anonymous function) @ system.src.js:3575(anonymous function) @ system.src.js:3960(anonymous function) @ system.src.js:4419(anonymous function) @ system.src.js:4671(anonymous function) @ system.src.js:406ZoneDelegate.invoke @ angular2-polyfills.js:332Zone.run @ angular2-polyfills.js:227(anonymous function) @ angular2-polyfills.js:576ZoneDelegate.invokeTask @ angular2-polyfills.js:365Zone.runTask @ angular2-polyfills.js:263drainMicroTaskQueue @ angular2-polyfills.js:482ZoneTask.invoke @ angular2-polyfills.js:434
angular2-polyfills.js:332 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal(…)
虽然我可以看到 node_modules\ng2-bs3-modal
是存在的.
Although I can see that node_modules\ng2-bs3-modal
is existing.
这里出了什么问题?
推荐答案
您需要配置 SystemJS 以从库中加载正确的文件.
You need to configure SystemJS to load right files from the library.
您可以尝试以下配置:
<script>
System.configure({
map: {
'ng2-bs3-modal': 'node_modules/ng2-bs3-modal'
},
packages: {
'ng2-bs3-modal': {
format: 'register',
defaultExtension: 'js'
}
}
});
(...)
</script>
这篇关于angular 2 + npm 安装包不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文