Next.js Discord

Discord Forum

I have trouble when use wasm with api/handler/route.ts.

Unanswered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
I have trouble when use wasm with api/handler/route.ts.

error says that:

wasm not file can't find.

Even if I use copy-webpack-plugin to copy that.
While my local mac works well, but running with bug in remote vercel .
And this is my next.config file:

import CopyWebpackPlugin from "copy-webpack-plugin";
import path from "path";

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
missingSuspenseWithCSRBailout: false,
},
webpack: (config, { isServer, dev, dir }) => {
config.experimental = {};
config.module.rules.push({
test: /.wasm$/,
type: "webassembly/async",
});
if (isServer) {
if (dev) {
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve("node_modules/kzg-wasm/dist/wasm/kzg.wasm"),
to: path.resolve(".next/server/wasm/kzg.wasm"),
},
],
})
);
} else {
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve("node_modules/kzg-wasm/dist/wasm/kzg.wasm"),
to: path.resolve(".next/server/app/api/wasm/kzg.wasm"),
},
],
})
);
}
}
return config;
},
};

export default nextConfig;
I have tried many ways. But it still can't work.

0 Replies