我正在使用 vercel 的忽略构建步骤字段来禁用预览部署(IE - 仅在分支为主分支时才部署)
\n我使用以下 bash 脚本执行此操作:
\nif [[ "$VERCEL_GIT_COMMIT_REF" == "main" ]] ; then\n # Proceed with the build\n echo "\xe2\x9c\x85 - Build can proceed"\n exit 1;\nelse\n # Don't build\n echo " - Build canceled"\n exit 0;\nfi\nRun Code Online (Sandbox Code Playgroud)\n现在,我的另一个要求是仅在更改的文件属于特定文件夹时才进行部署。我可以以某种方式将这两个要求结合在同一个脚本中吗?
\n如何访问此 bash 脚本中已提交文件的路径?
\n谢谢!
我正在尝试使用此处的说明将 Turborepo示例应用程序部署到 Vercel ,并收到错误:
Error: No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"
Run Code Online (Sandbox Code Playgroud)
我该如何修复它?
我正在尝试使用 getStaticProps 和 next js 从 api 获取一些数据。它返回错误 undefined cannot be serialized as JSON. Please usenull` 或省略此值。
我已经根据网上提出的有关该主题的解决方案修改了代码,但它们都不起作用。
export async function getStaticProps() {
const propertyForSale = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-sale&hitsPerPage=6`);
const propertyForRent = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-rent&hitsPerPage=6`);
return {
props: {
// Initial code
propertyForSale: propertyForSale?.hits,
propertyForRent: propertyForRent?.hits,
// the below snippet fixes the issue but return null
// propertyForSale: propertyForSale?.hits ?? null,
//propertyForRent: propertyForRent?.hits ?? null,
//the below snippet fixes the issue but return Unexpected token u in JSON at position 0 …Run Code Online (Sandbox Code Playgroud) 我在 Vercel 上使用 NextJs 一段时间了,因为它具有令人惊叹的开发体验和性能,但直到现在我才需要在我的任何应用程序中使用带有 WebSocket 的实时数据。
然而,目前我正在开发一个需要实时的新项目,但我正在努力决定如何实现 WebSockets。
简单介绍一下,该应用程序是一个实时交易市场,用户可以在其中用虚拟资产交换金钱。因此,需要 WebSocket 来让客户了解市场上的新列表,以及每隔几秒运行一次后台作业来跟踪交易是否完成、取消等。
请记住,我想继续使用 Vercel 上托管的 NextJs,我的问题是:我应该在使用 NextJs 时创建一个单独的服务器来处理所有实时数据和后台作业,还是应该使用普通的 React + ExpressJs + WebSockets服务器?我也考虑过使用 AWS 服务,但我认为它比其他两种选择更棘手。
如果我要创建一个单独的服务器,那么使用无服务器函数(在 Vercel 上创建)执行数据库操作然后通知 WebSocket 服务器复制更改(例如创建新的项目列表)是否理想?或者我应该使用 WebSocket 服务器的路由(ExpressJs 路由)来执行需要复制到客户端的那些类型的任务?
我有一个 nextjs 和 firebase 应用程序设置,具有功能,并且所有内容都可以在本地完美运行和构建。但是,当我构建并部署到 Vercel 时,我在 Vercel 控制台中收到以下构建错误:
类型错误:找不到模块“firebase-functions”或其相应的类型声明。
这是我的应用程序/功能 package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"axios": "^0.26.1",
"firebase": "^9.6.11",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": …Run Code Online (Sandbox Code Playgroud) 这是我的下一个 js 项目的一部分。该网站在 localhost 上完美运行,但当我将其部署在 vercel 上时,/blogs/book/chapter 页面给出文件未找到,在此处输入图像描述 500 错误。
import fs from "fs";
import path from "path";
import Head from "next/head";
import DefaultErrorPage from "next/error";
import { useRouter } from "next/router";
import matter from "gray-matter";
import { marked } from "marked";
import styles from "../../../../styles/blog/Chapter.module.css";
import { capitalise } from "../../../../components/blog/Capitalise";
import BlogPostBottom from "../../../../components/blog/BlogPostBottom";
export default function Chapter({ book, chapter, frontmatter, content }) {
// Destructuring
const { description …Run Code Online (Sandbox Code Playgroud) 我有 nextjs api 路由/api/auth/signout,它基本上只是清除特定的 cookie 并发送回 JSON。
问题是,当我在 Vercel 中部署项目时,这个特定的 API 第一次正常工作(cookie 清除并给出 200 响应),但后来它不起作用(cookie 未清除并给出 304 响应)。
我想知道,有什么办法可以避免只针对这条路线进行缓存吗?
解决这个问题的最佳方法是什么?
@googlemaps/js-api-loader我正在我的 Nuxt 3 网站中使用。在本地开发中一切正常,但是当我尝试使用nuxt generate(无论是在本地还是在 Vercel 上)构建项目时,我收到以下错误:
[nuxt] [request error] Named export 'Loader' not found. The requested module 'file:///path/to/website/node_modules/@googlemaps/js-api-loader/dist/index.umd.js' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using:
Run Code Online (Sandbox Code Playgroud)
加载脚本的重要部分如下所示:
[nuxt] [request error] Named export 'Loader' not found. The requested module 'file:///path/to/website/node_modules/@googlemaps/js-api-loader/dist/index.umd.js' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported …Run Code Online (Sandbox Code Playgroud) 您好,我正在为我的博客使用无头 cms“next-wordpress-starter”,并添加了一个中间件来处理来自“x”站点的流量,并将其重定向回该站点。在本地环境中它工作完美,但是当我部署在 vercel 中时它显示此错误:500:INTERNAL_SERVER_ERROR 代码:EDGE_FUNCTION_INVOCATION_FAILED
import { NextResponse } from 'next/server';
export function middleware(req) {
let referrer_path1 = req.referrer;
console.log(referrer_path1);
if (referrer_path1.includes('x-domain')) {
let redirect_url = `https://x-domain/${req.nextUrl.pathname}`;
return NextResponse.redirect(redirect_url);
}
return NextResponse.next();
}
Run Code Online (Sandbox Code Playgroud)
是 vercel 方面的问题还是这种路由有其他解决方案?
我在初始页面加载时经常遇到看似随机的错误。我认为问题与 Vercel Serverless Functions 有关。
\n\nVercel 的完整日志:
\n[GET] /\n14:54:19:39\n2022-07-21T12:54:19.426Z 3a175b6b-396b-45d5-b1a1-46072201cd6a ERROR Unhandled Promise Rejection \n{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"FetchError: request to \nhttps://api-eu-central-1.graphcms.com/v2/cl2k6hi1809a401xk4hd3h5zj/master failed, reason: \nClient network socket disconnected before secure TLS connection was \nestablished","reason":{"errorType":"FetchError","errorMessage":"request to https://api-\neu-central-1.graphcms.com/v2/cl2k6hi1809a401xk4hd3h5zj/master failed, reason: Client \nnetwork socket disconnected before secure TLS connection was \nestablished","code":"ECONNRESET","message":"request to https://api-eu-central-\n1.graphcms.com/v2/cl2k6hi1809a401xk4hd3h5zj/master failed, reason: Client network socket \ndisconnected before secure TLS connection was \nestablished","type":"system","errno":"ECONNRESET","stack":["FetchError: request to \nhttps://api-eu-central-1.graphcms.com/v2/cl2k6hi1809a401xk4hd3h5zj/master failed, reason: \nClient network socket disconnected before secure TLS connection was established"," at \nClientRequest.<anonymous> (/var/task/index.js:7892:18)"," …Run Code Online (Sandbox Code Playgroud)