【问题标题】:jQuery file is not found in node.js + Express app deployed on Heroku在 Heroku 上部署的 node.js + Express 应用程序中找不到 jQuery 文件
【发布时间】:2016-03-31 00:23:41
【问题描述】:

我在 Heroku 上部署了一个 node.js + Express + express-handlebars 应用程序。运行应用程序时,控制台显示找不到 jquery 文件 (404) 错误。这会产生级联效应,导致 Bootstrap、Datatables 等依赖库失败。

以下是我的package.json文件

{
  "name": "test-node",
  "version": "0.0.1",
  "description": "Test node",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/username/repo.git"
  },
  "author": "Neeraj Jadhav",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/username/repo/issues"
  },
  "homepage": "https://github.com/username/repo",
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.15.0",
    "cookie-parser": "^1.4.1",
    "express": "^4.13.4",
    "express-handlebars": "^3.0.0",
    "express-session": "^1.13.0",
    "method-override": "^2.3.5",
    "moment": "^2.12.0",
    "mysql": "^2.10.2",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "sendgrid": "^2.0.0",
    "serve-favicon": "^2.3.0",
    "shortid": "^2.2.4"
  },
  "engines": {
    "node": "0.10.28",
    "npm": "1.4.9"
  }
}

以下是我的node js项目文件夹结构截图。

找不到jquery-1.12.1.min.js

在我的 app.js 中,我将引用静态文件的代码行移到了其他所有人之上,但它仍然不起作用。如果我在新选项卡中打开 jquery Heroku 链接并在 js 之前添加 public,如下所示:https://admin-violet.herokuapp.com/public/js/jQuery-1.12.1.min.js,它会显示相同的错误。

知道为什么找不到 jquery 文件吗?我之前在 Heroku 上部署过 node js 项目,但从未遇到过这个问题。

感谢您的帮助。

【问题讨论】:

    标签: javascript jquery node.js express heroku


    【解决方案1】:

    heroku 和 node 需要使用小写字母,注意错误是在寻找 jQuery,只要指向 jquery 就可以了。

    相关文档:

    Heroku Docs

    某些语言鼓励使用与类名匹配的文件名,例如 MyClass 和“MyClass.js”。不要在节点中这样做。而是使用小写文件:

    let MyClass = require('my-class');
    

    Node.js 是少有的以 Linux 为中心的工具,具有出色的跨平台支持。虽然 OSX 和 Windows 会同等对待“myclass.js”和“MyClass.js”,但 Linux 不会。要编写可在平台之间移植的代码,您需要完全匹配 require 语句,包括大小写。 解决这个问题的简单方法是对所有内容都使用小写文件名,例如“my-class.js”。

    【讨论】:

      【解决方案2】:

      在您的命令行工具中 - 尝试重新启动 Heroku 服务器。 heroku restart 或尝试阅读日志heroku logs -t "-t" 是 tail 的标志,它将向您显示 Heroku 中服务器端出错的位置。

      【讨论】:

        猜你喜欢
        • 2018-06-19
        • 2021-09-02
        • 1970-01-01
        • 1970-01-01
        • 2014-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多