简体   繁体   English

在部署在 Heroku 上的 node.js + Express 应用程序中找不到 jQuery 文件

[英]jQuery file is not found in node.js + Express app deployed on Heroku

I have a node.js + Express + express-handlebars app deployed on Heroku.我在 Heroku 上部署了一个 node.js + Express + express-handlebars 应用程序。 When running the app the console shows that the jquery file was not found (404) error.运行应用程序时,控制台显示未找到 jquery 文件 (404) 错误。 This creates a cascading effect and resulting dependant libraries like Bootstrap, Datatables etc fail.这会产生级联效应,导致 Bootstrap、Datatables 等依赖库失败。

The following is my package.json file以下是我的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"
  }
}

The following is the screenshot of my node js project folder structure.下面是我的node js项目文件夹结构截图。

nodejs项目结构

It is unable to find the jquery-1.12.1.min.js找不到 jquery-1.12.1.min.js

控制台上的错误

In my app.js I moved the line of code referencing the static files above everyone else, but it still does not work.在我的 app.js 中,我将引用静态文件的代码行移到了其他所有人之上,但它仍然不起作用。 If I open the jquery Heroku link in a new tab and add public before js, like this: https://admin-violet.herokuapp.com/public/js/jQuery-1.12.1.min.js , it shows the same error.如果我在新选项卡中打开 jquery Heroku 链接并在 js 之前添加 public,如下所示: https://admin-violet.herokuapp.com/public/js/jQuery-1.12.1.min.js ,它显示相同错误。

app.js 代码

Any idea on why it is unable to find the jquery file?关于为什么找不到 jquery 文件的任何想法? I have deployed node js projects on Heroku before but never faced this issue.我之前在 Heroku 上部署过 node js 项目,但从未遇到过这个问题。

Appreciate the help.感谢帮助。

You need to use lowercase letters for heroku and node, note the error is looking for jQuery , just point it to jquery and you should be good.您需要对 heroku 和 node 使用小写字母,请注意错误正在寻找jQuery ,只需将其指向jquery 就可以了。

Relevant Docs:相关文档:

Heroku Docs Heroku 文档

Some languages encourage filenames that match class names, like MyClass and 'MyClass.js'.某些语言鼓励使用与类名匹配的文件名,例如 MyClass 和“MyClass.js”。 Don't do that in node.不要在节点中这样做。 Instead, use lowercase files:相反,使用小写文件:

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

Node.js is the rare example of a Linux-centric tool with great cross-platform support. Node.js 是具有强大跨平台支持的以 Linux 为中心的工具的罕见示例。 While OSX and Windows will treat 'myclass.js' and 'MyClass.js' equivalently, Linux won't.虽然 OSX 和 Windows 会同等对待“myclass.js”和“MyClass.js”,但 Linux 不会。 To write code that's portable between platforms, you'll need to exactly match require statements, including capitalization.要编写可在平台之间移植的代码,您需要完全匹配 require 语句,包括大写。 The easy way to get this right is to just stick with lowercase filenames for everything, eg 'my-class.js'.解决这个问题的简单方法是对所有内容都使用小写文件名,例如“my-class.js”。

In your command line tool - try to restart the Heroku server.在您的命令行工具中 - 尝试重新启动 Heroku 服务器。 heroku restart or try to read the logs heroku logs -t the "-t" is a flag for tail will show you where it errors out on the server side within Heroku. heroku restart或尝试读取日志heroku logs -t "-t" 是 tail 的标志将显示它在 Heroku 中服务器端出错的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM