transformers.js
transformers.js copied to clipboard
Vercel Deployment Issues - Onyruntime Errors With Xenova
System Info
Mac m2 Chrome "@xenova/transformers": "^2.16.0",
Environment/Platform
- [X] Website/web-app
- [ ] Browser extension
- [ ] Server-side (e.g., Node.js, Deno, Bun)
- [ ] Desktop app (e.g., Electron)
- [X] Other (e.g., VSCode extension)
Description
Im getting these errors for xenova (local embeddings) when deployment to vercel...I found another post where on github where some users were shoing soluations but those did not work for me.
Anyone else having these
Reproduction
I cant reporduce t. Its on vercel everytiem when using the most updated veriosn - "@xenova/transformers": "^2.16.0",
Did you add this custom webpack
config on next.config.js
file?
I find that it should at least have these two things:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["sharp", "onnxruntime-node"],
},
webpack: (config) => {
// Ignore node-specific modules when bundling for the browser
// https://webpack.js.org/configuration/resolve/#resolvealias
config.resolve.alias = {
...config.resolve.alias,
sharp$: false,
"onnxruntime-node$": false,
};
return config;
},
}
I myself encounter more issues beyond this (something to do with importing the onnxruntime-node
that required me to patch a few lines of the transformers.js
package. Still checking if that's only on my project, but let me know if you run into other issues. I'll be happy to share. I was able to run inference on a Next.js route (node runtime) deployed on Vercel.
@kvnang Thanks a bunch man! I will check that out tomorrow first thing and get back to you. Yeah this has been a pesky one. I had to just remove it from my retrieval flow for now until i could figure it out! Will check in next day or two
@kvnang I tried your added script to nextconfig and it worked! Cant believe i didnt see that anywhere! Thanks so much for the help!
Did you add this custom
webpack
config onnext.config.js
file?I find that it should at least have these two things:
/** @type {import('next').NextConfig} */ const nextConfig = { experimental: { serverComponentsExternalPackages: ["sharp", "onnxruntime-node"], }, webpack: (config) => { // Ignore node-specific modules when bundling for the browser // https://webpack.js.org/configuration/resolve/#resolvealias config.resolve.alias = { ...config.resolve.alias, sharp$: false, "onnxruntime-node$": false, }; return config; }, }
I myself encounter more issues beyond this (something to do with importing the
onnxruntime-node
that required me to patch a few lines of thetransformers.js
package. Still checking if that's only on my project, but let me know if you run into other issues. I'll be happy to share. I was able to run inference on a Next.js route (node runtime) deployed on Vercel.
I am running into this issue specifically when using ClipEmbedding with Vercel.
https://github.com/neondatabase/examples/tree/main/ai/llamaindex/reverse-image-search-nextjs is my minimal reproducible.