简体   繁体   中英

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. When running the app the console shows that the jquery file was not found (404) error. This creates a cascading effect and resulting dependant libraries like Bootstrap, Datatables etc fail.

The following is my package.json file

{
  "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.

nodejs项目结构

It is unable to find the 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. 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.

app.js 代码

Any idea on why it is unable to find the jquery file? I have deployed node js projects on Heroku before but never faced this issue.

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.

Relevant Docs:

Heroku Docs

Some languages encourage filenames that match class names, like MyClass and '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. While OSX and Windows will treat 'myclass.js' and 'MyClass.js' equivalently, Linux won't. To write code that's portable between platforms, you'll need to exactly match require statements, including capitalization. The easy way to get this right is to just stick with lowercase filenames for everything, eg 'my-class.js'.

In your command line tool - try to restart the Heroku server. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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