尝试部署到Heroku时出现“找不到模块'异步'”错误

时间:2018-12-08 06:53:18

标签: javascript node.js asynchronous heroku deployment

当尝试部署到Heroku时,我没有遇到任何问题,但是当尝试访问我的Heroku URL时,我得到了"Application error"。执行heroku logs后,出现错误Cannot find module 'async'。我安装了它,而我async/await仅在此函数内部。有人可以帮我解决这个问题吗?

const express = require('express');
const router = express.Router();
const Rental = require('../models/rental');
const User = require('../models/user');
const { normalizedErrors } = require('../helpers/mongoose')
var flatten = require('array-flatten')
var Promise = require('Promise');
var async = require('async');

router.get('', async function (req, res) {
  let finalResults = [];

  let dummyArray = [''];
  let resolvedFinalArray = await Promise.all(dummyArray.map(async (value) => {
    const result = await getRentalsByQuery({});
    finalValue = result;
    return finalValue;
  }));
  finalResults.push(resolvedFinalArray);
  finalResults = flatten(finalResults);



  if (req.query.filters) {
    const queryObj = JSON.parse(req.query.filters);
    if (queryObj.title) {
      // SOME ASYNC OPERATIONS with foundRentals
    }
  }


  //clean resolvedFinalArray for sending as a simple array json
  finalResults = flatten(finalResults)
  res.json(finalResults);
});

这是错误详细信息:

2018-12-08T06:09:01.416754+00:00 app[web.1]:
2018-12-08T06:09:02.649330+00:00 app[web.1]: internal/modules/cjs/loader.js:582
2018-12-08T06:09:02.649344+00:00 app[web.1]: throw err;
2018-12-08T06:09:02.649346+00:00 app[web.1]: ^
2018-12-08T06:09:02.649347+00:00 app[web.1]:
2018-12-08T06:09:02.649348+00:00 app[web.1]: Error: Cannot find module 'async'
2018-12-08T06:09:02.649350+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
2018-12-08T06:09:02.649351+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:506:25)
2018-12-08T06:09:02.649353+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2018-12-08T06:09:02.649354+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2018-12-08T06:09:02.649355+00:00 app[web.1]: at Object.<anonymous> (/app/server/routes/rentals.js:8:13)
2018-12-08T06:09:02.649357+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-12-08T06:09:02.649358+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-12-08T06:09:02.649359+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-12-08T06:09:02.649361+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-12-08T06:09:02.649362+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:529:3)
2018-12-08T06:09:02.649363+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2018-12-08T06:09:02.649364+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2018-12-08T06:09:02.649365+00:00 app[web.1]: at Object.<anonymous> (/app/server/index.js:8:22)
2018-12-08T06:09:02.649367+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-12-08T06:09:02.649368+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-12-08T06:09:02.649369+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-12-08T06:09:02.672674+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-08T06:09:02.673564+00:00 app[web.1]: npm ERR! errno 1
2018-12-08T06:09:02.676119+00:00 app[web.1]: npm ERR! server@1.0.0 start: `node index.js`
2018-12-08T06:09:02.676416+00:00 app[web.1]: npm ERR! Exit status 1
2018-12-08T06:09:02.677167+00:00 app[web.1]: npm ERR!
2018-12-08T06:09:02.677417+00:00 app[web.1]: npm ERR! Failed at the server@1.0.0 start script.
2018-12-08T06:09:02.677805+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-12-08T06:09:02.696205+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-12-08T06:09:02.697621+00:00 app[web.1]:
2018-12-08T06:09:02.698037+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-12-08T06:09:02.698297+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-12-08T06_09_02_682Z-debug.log
2018-12-08T06:09:02.713718+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-08T06:09:02.714599+00:00 app[web.1]: npm ERR! errno 1
2018-12-08T06:09:02.718363+00:00 app[web.1]: npm ERR! angular-starter@0.0.0 start: `npm run start --prefix server`
2018-12-08T06:09:02.718847+00:00 app[web.1]: npm ERR! Exit status 1
2018-12-08T06:09:02.719560+00:00 app[web.1]: npm ERR!
2018-12-08T06:09:02.719990+00:00 app[web.1]: npm ERR! Failed at the angular-starter@0.0.0 start script.
2018-12-08T06:09:02.720570+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-12-08T06:09:02.735159+00:00 app[web.1]:
2018-12-08T06:09:02.735523+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-12-08T06:09:02.735769+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-12-08T06_09_02_724Z-debug.log
2018-12-08T06:09:14.369444+00:00 app[web.1]:
2018-12-08T06:09:14.369473+00:00 app[web.1]: > angular-starter@0.0.0 start /app
2018-12-08T06:09:14.369475+00:00 app[web.1]: > npm run start --prefix server
2018-12-08T06:09:14.369477+00:00 app[web.1]:
2018-12-08T06:09:15.403449+00:00 app[web.1]:
2018-12-08T06:09:15.403494+00:00 app[web.1]: > server@1.0.0 start /app/server
2018-12-08T06:09:15.403496+00:00 app[web.1]: > node index.js
2018-12-08T06:09:15.403497+00:00 app[web.1]:

2 个答案:

答案 0 :(得分:0)

首先npm i --save async,然后重新启动应用程序

答案 1 :(得分:0)

在node_modules中检查'async',因为您的加载程序日志“找不到模块'async'”