我正在尝试部署我的 NextJs 应用程序。过去几天我也遇到了同样的两个错误:
1: // 稍后会出错
2: 错误:未构建无服务器页面。了解更多: https: //err.sh/vercel/vercel/now-next-no-serverless-pages-built
我不知道如何修复它们。如果有人提供帮助,我将不胜感激
这是我的 package.json 文件:
{
"name": "my-dev-portfolio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next",
"bulid": "next build",
"start": "next start",
"now-build": "next build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"next": "^12.2.0",
"react-dom": "^18.2.0",
"typewriter-effect": "^2.19.0"
}
}
Run Code Online (Sandbox Code Playgroud)
next.config.json 文件:
module.exports = {
target: "serverless"
}
Run Code Online (Sandbox Code Playgroud)
now.json 文件: …
我将 Nextjs 应用程序部署到 Vercel,但我的 api 调用失败,响应为 500,即使它在 localhost 上运行也是如此。我可以使用 获得初始负载getStaticProps,所以我相信与数据库的连接是可以的。
我的getStaticPaths功能正常工作如下所示:
export async function getStaticProps() {
dbConnect();
const properties = await Property.find({
deletedAt: { $exists: false },
archivedAt: { $exists: false },
})
.sort({ refreshed: -1 })
.limit(itemsPerPage);
const propertiesCount = await Property.countDocuments(
{ deletedAt: { $exists: false }, archivedAt: { $exists: false } },
{ limit: 100 }
);
const pagesCount = Math.ceil(propertiesCount / itemsPerPage);
return {
props: {
fetchedProperties: properties.map((property) => propertyToJson(property)),
pagesCount: pagesCount, …Run Code Online (Sandbox Code Playgroud) 我有一个包含两个项目的 monorepo -web和docs. 其中每个都是自己的 Vercel 项目,该web项目安装在https://example.com并docs安装在https://docs.example.com。所有这一切都按预期进行。
我现在希望该项目可以在https://example.com/docsdocs上使用。在项目中,我在文件中设置了以下重写。webvercel.json
{
"rewrites": [
{
"source": "/docs/:match*",
"destination": "https://docs.example.com/:match*"
},
{ "source": "/(.*)", "destination": "/" }
]
}
Run Code Online (Sandbox Code Playgroud)
这适用于主索引文件,但所有相应的 css 和 js 文件都会导致 404。浏览器正在https://example.com/_next查找这些文件,这是不正确的,它应该查看https://docs.example.com/_next。
我该如何进行这项工作?
最近,我决定在一个小项目中尝试 vercel,但在使用 sendgrid 和 vercel 时遇到了问题。我之前已经在heroku上将sendgrid实现到nodejs/express项目中,没有任何问题,但由于某种原因Vercel无法工作。
更糟糕的是,sendgrid 没有给出任何错误,因此很难排除故障。承诺永远悬而未决。测试时,本地一切正常,我已确认环境变量正确并正在加载。
这是我的代码:
const sgMail = require('@sendgrid/mail');
const { magicLinkTemplate } = require('./templates');
const sendEmail = async (msg) => {
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
try {
await sgMail.send(msg)
} catch (error) {
console.error(error);
if (error.response) {
console.error(error.response.body)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了多次迭代,但每次都失败了。还有其他人在使用 vercel 和 sendgrid 时遇到过问题吗?
我有个问题。我创建了一个 url 缩短网站,typescript它是一个单页网站,但可以更改路线。在我使用的这个项目中webpack,对于我使用的开发服务器webpack-dev-server以及返回index.html几乎所有路由,我在以下位置编写了这段代码webpack.config.js:
devServer: {
static: {
directory: path.join(__dirname, "dist"),
},
compress: true,
proxy: {
"/**": {
target: "/index.html",
secure: false,
bypass: function (req, res, opt) {
if (
req.path.indexOf("/img/") !== -1 ||
req.path.indexOf("/public/") !== -1
) {
return "/";
}
if (req.path.indexOf("/build.css") !== -1) {
return "/build.css";
}
if (req.headers.accept.indexOf("html") !== -1) {
return "/index.html";
} else return;
},
},
},
}
Run Code Online (Sandbox Code Playgroud)
现在我想index.html为应用程序的 vercel 服务器启用此功能(每次路由更改时返回)。这时,当我改变路线时,我会得到404页面。但我想得到index.html。我进行了很多搜索来实现我想要的,并且测试了一些方法,但我无法做到我想要的。 …
我已经使用 Express + TypeScript 上传了带有节点的项目。此应用程序生成一个dist用于构建的文件夹,但当 vercel 部署我的应用程序时,它不会运行命令构建,因此我为部署我的应用程序所做的就是在本地构建并上传此dist文件夹。这是我的 vercel.json
{
"version": 2,
"buildCommand": "yarn build",
"devCommand": "yarn dev",
"outputDirectory": "dist",
"builds": [
{
"src": "dist/index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/index.js"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我在 vercel.json 中有两次重写,但只有其中之一有效:
{
"rewrites": [
{
"source": "/vault/:path*",
"destination": "http://vault-snail.vercel.app/:path*"
},
{
"source": "/",
"destination": "https://vault-extracter.wordpress.com"
},
],
"cleanUrls": true
}
Run Code Online (Sandbox Code Playgroud)
我想重写从 maildomain.com/vault 到http://vault-snail.vercel.app(这就是有效的情况)的所有内容。而且,我希望根页面能够逐https://vault-extracter.wordpress.com页重写。这种情况是行不通的。无论我如何尝试,似乎我都无法重写页面的根目录。
有什么方法或想法可以解决这个问题吗?
Vercel 不会在 Github 上触发新的提交。
大家好!很好,但 Vercel 部署了提交,但没有进行任何更改。我以为我没有推动这些改变,但我做到了。我不知道为什么突然这样,但很奇怪。
任何解决方案将不胜感激!
我尝试重新部署,但没有什么区别。我期待 Vercel 正确部署我的项目。
正如标题所示,ESLint 抱怨此错误消息:
ESLint: Unable to resolve path to module '@vercel/analytics/react'.(import/no-unresolved)
Run Code Online (Sandbox Code Playgroud)
在行中:import { Analytics } from '@vercel/analytics/react';
按照此Vercel 快速入门指南中的说明操作时,使用 Next.js。
总而言之,指令是:
1-通过NPM安装包
npm install @vercel/analytics
Run Code Online (Sandbox Code Playgroud)
2-在/pages/_app.tsx文件中,导入它:
import { Analytics } from '@vercel/analytics/react';
function MyApp({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<Analytics />
</>
);
}
export default MyApp;
Run Code Online (Sandbox Code Playgroud)
我使用的包:
"next": "^12.1.0",
"react": "17.0.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-next": "^12.2.5",
"eslint-config-prettier": "^6.15.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^24.7.0",
"eslint-plugin-jsx-a11y": "^6.5.1", …Run Code Online (Sandbox Code Playgroud) 我正在尝试为大学的在线实验建立一个网站。为此,我在几个月前接触了 MERN 堆栈,并且或多或少在本地完成了该网站。现在,每当我通过 Vercel 切换到生产版本时,与数据库的后端连接都会抛出405 错误。
使用之前版本的官方文档,我能够启动相同的连接,但除 Chrome 之外的任何浏览器都不允许我获取数据。因此,我将整个后端从 YouTube 教程更改为这个 GitHub 存储库。该解决方案在开发版本中再次完美运行,但在生产中却失败了。经过一些调试后,我发现问题出在我传递的.post(URL)中(在 /src/Pages/Home1.js 中):
import axios from "axios";
(...)
axios
.post("/api/participants", passvalue)
.then(() => {
console.log("new participant added with AXIOS");
})
.catch((e) => {
console.log("Unable to add with AXIOS: ", e);
});
(...)
Run Code Online (Sandbox Code Playgroud)
在本地构建中,完整的 URL 是在我的.envhttp://localhost:5001/api/participants文件中定义 PORT 5001 的位置。默认情况下,此 URL 应创建GET请求并根据我的路由(/server/routes/participants.js) 列出所有虚拟 mongodb 条目:
const express = require("express");
const router = express.Router();
const …Run Code Online (Sandbox Code Playgroud)