gpt4 book ai didi

javascript - 无法在 Angular 1 的客户端找到 node_modules

转载 作者:行者123 更新时间:2023-11-29 19:07:16 42 4
gpt4 key购买 nike

我正在尝试在我的 Angular 1 应用程序中加载一个非 Angular 库。

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。

如果有人能帮我解决这个问题,那将会很有帮助。感谢您的宝贵时间和帮助。

最佳答案

这是因为在前端(客户端)您使用 bower 来管理依赖项,以便在成功运行 gulp 任务后不会包含 nodemodules。您需要修改 gulp 任务以包含 node_modules。这是因为从您的示例中我了解到您正在使用 gulp 作为任务运行器,当您运行 gulp serve(或运行应用程序的任务)时,将在该 bower 中创建 dist 文件夹,但不会包含 node_modules。您的所有应用程序正在通过 dist 文件夹运行。

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

这将解决您的问题。

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

关于javascript - 无法在 Angular 1 的客户端找到 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41940266/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com