gpt4 book ai didi

server - 无法读取未定义的属性 'getCompilationErrors'

转载 作者:行者123 更新时间:2023-12-04 15:43:14 24 4
gpt4 key购买 nike

我在使用 nextJs 在无服务器上设置快速服务器实例时遇到问题。运行服务器功能时,我一直收到 Cannot read property 'getCompilationErrors' of undefined 的提示。这似乎是 app.render 的问题。

  • 运行调试时,它似乎来自 nextJs

服务器.js

const express = require('express');
const path = require('path');
const dev = process.env.NODE_ENV !== 'production';
const next = require('next');
const pathMatch = require('path-match');

const app = next({ dev });
const handle = app.getRequestHandler();
const { parse } = require('url');

const server = express();
const route = pathMatch();

server.use('/_next', express.static(path.join(__dirname, '.next')));

server.get('/', (req, res) => app.render(req, res, '/'));

server.get('*', (req, res) => handle(req, res));


module.exports = server;

索引.js


const sls = require('serverless-http')
const binaryMimeTypes = require('./binaryMimeTypes')

const server = require('./server')

module.exports.server = sls(server, {
binary: binaryMimeTypes
});

无服务器.yml


service: ssr-react-next

provider:
name: aws
runtime: nodejs8.10
stage: ${self:custom.secrets.NODE_ENV}
region: us-east-1
environment:
NODE_ENV: ${self:custom.secrets.NODE_ENV}

functions:
server:
handler: index.server
events:
- http: ANY /
- http: ANY /{proxy+}

plugins:
- serverless-apigw-binary
- serverless-domain-manager

custom:
secrets: ${file(secrets.json)}
apigwBinary:
types:
- '*/*'
customDomain:
domainName: ${self:custom.secrets.DOMAIN}
basePath: ''
stage: ${self:custom.secrets.NODE_ENV}
createRoute53Record: true
# endpointType: 'regional'
# if the ACM certificate is created in a region except for `'us-east-1'` you need `endpointType: 'regional'`

最佳答案

想出了一个解决办法,只需要用异步准备应用程序

   server.use(async(req, res, next) => {
await app.prepare();
next();
})

关于server - 无法读取未定义的属性 'getCompilationErrors',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56940915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com