Azure 托管节点应用找不到模块'async/each'



我已经将我的应用程序部署到Azure几个星期了,现在没有问题。然而,现在我已经将DB集成到后端,它抛出了日志流中看到的这个错误,并给浏览器一个500码。

Application has thrown an uncaught exception and is terminated: Error: Cannot find module 'async/each' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (D:homesitewwwrootnode_modulesmongooselibschema.js:11:12) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17)

猫鼬似乎是问题所在,所以当我排除它时,一切又好了。我尝试在包中包含async-each作为依赖项。json,但这没有帮助(我没有见过一个模块与/in之前,所以猜测这里)

同样在绝望的时刻,我试着把同样的应用程序推送到另一个Web应用程序服务,但它甚至没有部署。WebApiClient超时了——不管这意味着什么。

我将完全相同的应用程序部署到Heroku上,它运行得很好。

"use strict";
let express = require('express');
let path = require('path');
let favicon = require('serve-favicon');
let logger = require('morgan');
let cookieParser = require('cookie-parser');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let passport = require('passport');
let LocalStrategy = require('passport-local').Strategy;
let session = require('express-session');
//routes
let home = require('./routes/index');
let register = require('./routes/register');
let members = require('./routes/members');
let login = require('./routes/login');
let logout = require('./routes/logout');
let app = express();
app.locals.courses = require('./data/courses');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({secret:'anything'}));
app.use(passport.initialize());
app.use(passport.session());
//mongoose passport config
require('./db').then(mongoose => {
  mongoose.Promise = global.Promise;
  require('./models/user').then(User => {
    passport.use(new LocalStrategy(User.authenticate()));
    passport.serializeUser(User.serializeUser());
    passport.deserializeUser(User.deserializeUser());
  });
})

//allow CORS requests
app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
});
app.use('/', home);
app.use('/register', register);
app.use('/members', members);
app.use('/login', login);
app.use('/logout', logout);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.send(err.message);
  });
}
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
  res.status(err.status || 500);
  res.send(err.message);
});

module.exports = app;

我成功地将mongoose部署到Azure上,测试代码也运行良好。也许你的应用程序将使用package.json文件中devDependencies部分配置的任何模块。

作为Azure Web Apps作为生产Web服务器,如果你通过git部署你的应用程序,默认部署任务将运行npm install --production,它将忽略在develop mod中的依赖项。

因此,您可以尝试按照自定义部署脚本为node.js生成部署脚本并修改deploy.cmd,找到句子call :ExecuteCmd !NPM_CMD! install --production并修改为call :ExecuteCmd !NPM_CMD! install

同时,您可以按照https://learn.microsoft.com/en-us/azure/nodejs-specify-node-version-azure-apps升级Azure Web Apps运行时的node.js和npm版本,以避免嵌套的node_modules文件夹结构。

相关内容

  • 没有找到相关文章

最新更新