vercel - 在 SvelteKit 中将 esbuild 标记为外部依赖项
问题描述
我正在开发一个 SvelteKit 应用程序,并且我在 API 端点上使用 esbuild 来转换获取 POST 的代码。
我正在从 esbuild 导入 transformSync 来执行此操作:
import { transformSync } from 'esbuild';
这在运行开发服务器以及使用 SvelteKit 在本地构建和运行生产预览时都可以正常工作。但是,当我推送到生产环境时(在 Vercel 上,使用 vercel 适配器),我遇到了以下错误:
Error: The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
More information: The file containing the code for esbuild's JavaScript API (/var/task/index.js) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.
我尝试将以下内容添加到我的 SvelteKit Vite 配置中:
vite: {
ssr: {
external: ['esbuild']
}
}
和:
vite: {
optimizeDeps: {
exclude: ['esbuild']
}
}
都没有奏效。
谁能在这里指出我做错了什么的正确方向?
解决方案
推荐阅读
- java - spring boot @EnableConfigurationProperties 标记内部类发生异常
- javascript - 仅在所有转换结束后运行代码
- php - 空字符串爆炸返回一个长度为 1 的数组
- android - 找不到 com.android.tools.build:gradle:4.1.1
- excel - 如何在 Excel VBA 中绘制带轮廓的楔形?
- css - 表格单元格内的 Flex 框或宽度:尽管 flex-shrink:0,但 min-content 会缩小
- symmetricds - SymmetricDS 多节点组复制
- python - 如何从python中的列表中打印选定的数字?
- c - 如何在 C 中进行提示
- java - 当用户在程序运行时结束程序时,程序可以重复吗?