mardi 5 mars 2019

Heroku gives a ReferenceError and doesn't recognize '$' on a node app

I am trying to deploy a simple app on Heroku. It works perfectly locally. When I try to serve it on Heroku, I get the error below:

ReferenceError: $ is not defined

Why am I being told that the $ is an issue, even though it works perfectly when I run it locally? I get that error when I run heroku local web. When I try to deploy the app on heroku, the logs tell me that it fails when trying npm start. Although this is an issue, I figure it will not work if I do not get it running locally with heroku local web. The code is as follows:

src/js/app.js

App = {
  ...
};

$(function() { // THIS IS THE FAILING LINE.
  $(window).load(function() {
    // App.listen(process.env.PORT || 8000);
    App.init();
  });
});

src/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <link rel="shortcut icon" type="image/png" href="static/favicon.ico"/>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/box.css" rel="stylesheet", type="text/css">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    </head>
    <body>
      <div class="container" style="width: 850px;">
           ...
      </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="jquery.min.js"></script>
    <script src="js/app.js"></script>
    <!-- <script -->
  </body>
</html>

package.json

{
  "name": "theName",
  "version": "1.0.0",
  "description": "",
  "main": "truffle.js",
  "directories": {},
  "scripts": {
    "dev": "lite-server"
  },
  "author": "Me",
  "license": "MIT",
  "devDependencies": {
    "lite-server": "^2.3.0"
  }
}

Procfile

web:node src/js/app.js




Aucun commentaire:

Enregistrer un commentaire