【问题标题】:/dist/handsontable.full.js 404 Not Found with bower/dist/handsontable.full.js 404 找不到凉亭
【发布时间】:2015-10-29 09:08:09
【问题描述】:

我已经使用 bower 安装了 Handsontable,如 its documentation 所示:

凉亭安装handsontable --save

我将这些链接添加到 view.ejs

<script src="/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="/dist/handsontable.full.css">

但我在浏览器中遇到了以下 404 错误

"NetworkError: 404 Not Found - http://localhost:3000/dist/handsontable.full.js"
handson...full.js

"NetworkError: 404 Not Found - http://localhost:3000/dist/handsontable.full.css"
handson...ull.css
ReferenceError: Handsontable is not defined in  

var hot = new Handsontable(container, {

即使我尝试将链接更改为绝对文件位置(项目的根目录作为参考):

<script src="./bower_components/handsontable/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="./bower_components/handsontable/dist/handsontable.full.css">

我还是有同样的问题:

"NetworkError: 404 Not Found - http://localhost:3000/bower_components/handsontable/dist/handsontable.full.js"
handson...full.js
2
"NetworkError: 404 Not Found - http://localhost:3000/bower_components/handsontable/dist/handsontable.full.css"
handson...ull.css
ReferenceError: Handsontable is not defined


var hot = new Handsontable(container, {

--- 编辑 ----

这是我的项目结构,我在加载 jquery.js 时也有同样的问题

我尝试了this question 的所有解决方案,但它们都不起作用。

【问题讨论】:

  • 你能告诉我们你的文件结构吗?
  • 当您使用 express 创建项目并使用 bower 安装模块时,这是非常标准的结构。我将更新问题以显示我的项目结构
  • 看起来 express 阻止了对所有项目文件夹的访问,并且只提供 /public 文件夹中的所有静态资源
  • 你的索引文件似乎在一个子文件夹中,所以你可以尝试在你的路径中上一个文件夹:./../bower_components/handsontable/dist/handsontable.full.js
  • 我正在运行一个带有 express 的节点应用程序,并没有完全遇到这个问题,但除此之外我无能为力

标签: express bower handsontable


【解决方案1】:

这对我有用:

app.use("/bower_components", express.static(path.join(__dirname, 'bower_components'))); 

我的错误是这样写的:

app.use("bower_components", express.static(__dirname + '/bower_components')); // this is wrong

在我看来,我写什么并不重要

(./bower_components 或 ../bower_components)。

所有这些都对我有用:

<script src="../bower_components/handsontable/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="bower_components/handsontable/dist/handsontable.full.css">   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多