[英]Error: Cannot find module 'jquery' on node.js on Heroku
我正在嘗試將jquery和jsdom包含在Heroku上托管的node.js服務器中,以便可以從控制台(而不是從網頁)使用jQuery使用$ .ajax({...})進行ajax調用。
在Heroku上部署Node服務器時,我始終收到以下錯誤消息:
Error: Cannot find module 'jquery'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/server.js:19:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Process exited with status 1
這是我的package.json的樣子:
{
"name": "node-api",
"main": "server.js",
"dependencies": {
"body-parser": "1.17.1",
"express": "4.15.2",
"jquery": "3.2.1",
"jsdom": "10.1.0",
"mongoose": "4.9.9"
},
"engines": {
"node": "6.10.3"
}
}
這是我在server.js中包含jquery的方式:
global.jquery = require('jquery');
window.$ = window.jquery = jquery;
任何幫助將非常感激!
謝謝,
JS
似乎heroku沒有安裝新軟件包
您可以嘗試將npm cache的heroku標志設置為false,以強制重新獲取軟件包並再次部署
heroku config:set NODEMODULESCACHE=false
git commit -am 'build' --allow-empty
git push heroku master
heroku config:unset NODEMODULESCACHE
您可以使用節點獲取或類似的程序包。 自述文件中的示例代碼:
// json
fetch('https://api.github.com/users/github')
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
// catching network error
// 3xx-5xx responses are NOT network errors, and should be handled in then()
// you only need one catch() at the end of your promise chain
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.