【发布时间】:2019-11-11 02:07:39
【问题描述】:
我正在创建一个小应用程序来学习 angularjs 并使用 npm 安装它和其他依赖项。为了为应用程序提供服务,我在本地通过 npm 安装了 http-server 包。我的应用目录结构是这样的
餐厅 > 应用程序、node_modules、package.json
app 文件夹的样子
app > index.html, app.js
在我的 index.html 中,我尝试像这样从 node_modules 引用 angular.min.js 和引导 css 文件
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
<script src="../node_modules/angular/angular.min.js"></script>
<script src="../app.js"></script>
<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js>"></script>
在 app.js 内部,我声明了一个 angularjs 模块,因此我可以从我的 index.html 文件中打印插值结果。
package.json:
{
"name": "restaurant",
"version": "1.0.0",
"description": "An AngularJS app for Restaurants",
"author": "",
"license": "MIT",
"devDependencies": {
"http-server": "^0.11.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "http-server -a localhost -p 4000 ./app"
},
"dependencies": {
"angular": "^1.7.8",
"bootstrap": "^4.3.1"
}
}
当我运行 npm start 并转到 localhost:4000/index.html 它说
GET http://localhost:4000/node_modules/bootstrap/dist/css/bootstrap.min.css net::ERR_ABORTED 404 (Not Found)
index.html:4
GET http://localhost:4000/node_modules/angular/angular.min.js net::ERR_ABORTED 404 (Not Found)
app.js:1 Uncaught ReferenceError: angular is not defined
at app.js:1
(anonymous) @ app.js:1
index.html:6 GET
http://localhost:4000/node_modules/bootstrap/dist/js/bootstrap.min.js%3E net::ERR_ABORTED 404 (Not Found)
我的问题是我是否必须在我的包中编写一些命令才能将 angularjs 和其他库文件复制到我的应用程序目录的其他文件夹中?
如果不是,为什么 localhost:4000/index.html 找不到这些文件?
适用于任何解决方案的 TIA。
【问题讨论】:
标签: node.js angularjs npm node-modules