![](/img/trans.png)
[英]Jest encountered an unexpected token with Next.js and TypeScript when using createUserWithEmailAndPassword in firebase/auth
[英]Next.js on Firebase Functions with Typescript
我正在嘗試將Next.js
應用程序部署到Firebase Functions
。
import next from 'next'
import {https} from 'firebase-functions'
const server = next({
dev: process.env.NODE_ENV !== 'production',
conf: {distDir: '.next'}
})
const nextjsHandler = server.getRequestHandler()
exports.app = https.onRequest(async (req, res) => {
await server.prepare()
return await nextjsHandler(req, res)
})
問題是 Typescript 在以下兩個地方抱怨:
對於行conf: {distDir: '.next'}
它顯示以下錯誤(這很奇怪,因為我在Next.js 源中發現NextConfig
應該接受distDir
):
Type '{ distDir: string; }' is not assignable to type 'NextConfig'.
對於行return await nextjsHandler(req, res)
,特別是res
:
Type error: Argument of type 'Response<any>' is not assignable to parameter of type 'ServerResponse'. Property 'req' is optional in type 'Response<any>' but required in type 'ServerResponse'.
我真的很感激解決這兩個問題的任何幫助。 謝謝!
const isDev = process.env.NODE_ENV;== 'production';
但是在關注博客之后,我發現應用程序中沒有環境變量,這是導致代碼錯誤的原因。.env
文件和一個.env.sample
文件,之后我可以毫無錯誤地部署 function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.