我已经将我的应用程序部署到Azure几周了,没问题。但是现在我已经将数据库集成到了后端,它会在日志流中看到这个错误,并为浏览器提供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:\home\site\wwwroot\node_modules\mongoose\lib\schema.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)
猫鼬似乎是个问题,所以当我排除它时,一切都会好起来的。我尝试在我的package.json中包含async-each作为依赖项,但是没有帮助(我之前没有看到带有/ in的模块,所以在这里猜测)
同样在绝望的时刻,我尝试将同一个应用程序推送到另一个Web App服务,但它甚至无法部署。 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;
答案 0 :(得分:1)
我已成功将<repositories>
<repository>
<id>smartbear-sweden-repository</id>
<url>http://smartbearsoftware.com/repository/maven2/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://smartbearsoftware.com/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
部署到Azure,测试代码也运行良好。也许您的应用程序将使用mongoose
文件中devDependencies
部分中配置的任何模块。
作为Azure Web Apps作为生产Web服务器,如果您通过git部署应用程序,则默认情况下部署任务将运行package.json
,这将忽略develop mod中的依赖项。
因此,您可以尝试按照Custom Deployment Script生成node.js的deplotment脚本并修改npm install --production
,找到句子deploy.cmd
并修改为call :ExecuteCmd !NPM_CMD! install --production
。
同时,您可以按照https://docs.microsoft.com/en-us/azure/nodejs-specify-node-version-azure-apps升级node.js和npm版本的Azure Web Apps运行时,以避免嵌套的call :ExecuteCmd !NPM_CMD! install
文件夹结构。