2016-12-30 64 views
0

我一直在试图导入node_modules库到我的应用程序,但在控制台不断返回Angular 2如何在node_modules中导入库?

GET http://localhost:4200/node_modules/systemjs/dist/system.src.js 

没有找到。有没有人知道如何解决这个问题?

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>PrcApplication</title> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
    <script src="../node_modules/systemjs/dist/system.src.js"></script> 
</head> 
<body> 
    <app-root>Loading...</app-root> 
</body> 

</html> 
+0

请告诉我们'index.html'和'node_modules'的文件夹结构 –

回答

0

添加下面的下HTML页眉和尝试:

<base href="/"> 
0

添加script标签会导致一个AJAX调用这条道路,这是不是你想要的,因为在生产中,你node_modules文件夹不可用,并且只有dist文件夹可用。

在这些情况下,您需要将该特定文件导入到自己的js/ts文件中,以便将文件导入并与src文件一起打包。

我不知道你用什么打包捆绑,或者甚至你捆绑或不捆绑,但是你可以将它导入到你的app.module.ts或类似的地方。

通常有一个名为vendor.ts或pollyfill.ts的文件是专为这些东西而设计的。

相关问题