无法在角度1的客户端找到node_modules

时间:2017-01-30 16:00:44

标签: javascript angularjs node-modules

我正在尝试在angular 1 app中加载一个非角度库。

index.html有以下脚本:

<head>
<script type="text/javascript" src="../node_modules/@mylib/index.js" charset="utf-8"></script>
<script type="text/javascript"src="../bower_components/myOtherlib/index.js"charset="utf-8"></script>
</head>

我的目录结构是:

MyApp
- src
  - app
    - index.js
  - index.html
- node_modules
- bower_components
- package.json
- bower.json
- test
- gulpfile.js

我可以从index.html访问bower_components但不能访问node_modules。 所以我能够加载myOtherlib / index.js但不能加载@ mylib / index.js

当我加载index.html时出现错误:

获取http://localhost:3000/node_modules/@mylib/index.js 404(未找到)

我正在使用IntelliJ。

如果有人可以帮我解决这个问题会很有帮助。感谢您的时间和帮助。

1 个答案:

答案 0 :(得分:3)

这是因为在前端(clientside)中您使用bower来管理依赖项,以便在成功运行gulp任务后不会包含nodemodules。您还需要修改gulp任务以包含node_modules。 这是因为从你的例子我开始知道你正在使用gulp作为任务运行器,当你运行gulp服务(或运行应用程序的任务)将创建dist文件夹,包括但不是node_modules.All你的应用程序正在通过dist文件夹运行。

最后,您需要修改gulpfile.js以包含node_modules。

这将解决您的问题。

然后像这样包含node_modules / dist / lodash.js