【问题标题】:angular 2, unable to add underscore.js, 404 not found角度 2,无法添加 underscore.js,找不到 404
【发布时间】:2017-06-10 16:08:45
【问题描述】:

我正在尝试在我的 Angular 2 项目中添加 underscore.js 库。 我已经使用 npm 安装了它,并且我也在我的 index.html 中添加了 underscore.js 的脚本标签,但它仍然在控制台“GET http://localhost:4200/node_modules/underscore/underscore.js”中显示这个错误,状态为 404。

提前致谢。

* Project Folder Structure Image here *

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>ProjectEx</title>
  <link href="assets/stylesheets/bootstrap.css" rel="stylesheet">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <script src="node_modules/underscore/underscore.js"></script>

  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
  <app-root>Loading...</app-root>

  <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
    crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>

</html>

【问题讨论】:

    标签: angular underscore.js


    【解决方案1】:

    如果您使用 angular-cli ,则需要包含在 .angular-cli.json 中。 node_modules 文件夹在构建中不可用。

    scripts: [
    '../node_modules/underscore/underscore.js'
    ]
    

    【讨论】:

    • 是的,我的项目中有一个 .angular-cli.json 文件,我已经在脚本中添加了它,但它仍然无法正常工作。
    • 您不需要包含在 index.html 中。它应该在代码中可用。你怎么知道它不可用
    • 我以为问题出在 index.html 中,但在分页组件 html 文件中发现了问题。无论如何谢谢skeptor。
    猜你喜欢
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多