javascript - Heroku 给出 ReferenceError 并且在节点应用程序上无法识别“$”
问题描述
我正在尝试在 Heroku 上部署一个简单的应用程序。它在本地完美运行。当我尝试在 Heroku 上提供它时,我收到以下错误:
ReferenceError: $ is not defined
为什么我被告知这$
是一个问题,即使我在本地运行它时它工作得很好?当我运行 heroku local web 时出现该错误。当我尝试在 heroku 上部署应用程序时,日志告诉我尝试 npm start 时它失败了。虽然这是一个问题,但我认为如果我不使用 heroku 本地网络在本地运行它,它将无法工作。代码如下:
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>
包.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"
}
}
档案
web:node src/js/app.js
解决方案
推荐阅读
- python-3.x - 当使用多线程函数增加进度条值时,我的 tkinter GUI 冻结
- eclipse-hono - 如何获取已注册的 Hono 设备的历史传感器数据
- laravel - 安装后如何使用 npm 包(chart.js)?
- javascript - VuePress:试图找到一种基于文件夹版本命名自动更新侧边栏的方法
- php - 为什么 PayPal 定期无法验证或使 IPN 无效?
- go - 为什么这个基本的 go-routine 程序返回 true?
- r - Table() 函数,但用于邻接矩阵?
- pyqt5 - 大小不等的子代的 QHBoxLayout 的替代方案
- c# - 根据数据注释反映表/列名称
- powerbi - 如何在powerbi中做countifs