/public当我在本地开发时,当我将文件夹放入以下位置时会找到图像/src/:
# locally\n./src/public/images/\nRun Code Online (Sandbox Code Playgroud)\n\n然后,当我进行部署时,找不到图像。但是当我将 public 文件夹放在 src 之外时,会发现图像:
\n\n# deploy\n./public/images/\n./src/\nRun Code Online (Sandbox Code Playgroud)\n\n我将图像用作:
\n\n<img src="/images/my-image.jpg" alt="" />\nRun Code Online (Sandbox Code Playgroud)\n\n是否有我必须使用的配置设置?
\n\n完整结构:
\n\n|- .now/\n| |- project.json\n| \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 README.txt \n|- next.config.js\n|- now.json\n|- src/\n| |- .next/\n| | |- build-manifest.json\n| | |- react-loadable-manifest.json\n| | |- cache/\n| | |- server/\n| | \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 static/\n| |- pages/\n| \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 next-env.d.ts\nRun Code Online (Sandbox Code Playgroud)\n 我有一个 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) 我有一个包含两个项目的 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)