xmtp / xmtp-js

XMTP client SDKs for JavaScript applications.

Home Page:https://xmtp.org/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Vercel Deployment user_preferences_bindings_wasm_bg.wasm not found

HadiKhai opened this issue · comments

Describe the bug

Hello everyone!

I have a nextjs (appDir) application inside an nx monorepo. I was getting the user_preferences_bindings_wasm_bg.wasm error on development and builds

Then I checked the xmtp-nextjs example (xmtp next.config.js) and I adapted it to my monorepo

if (isServer) {
  if (!dev) {
    config.plugins.push(
      new CopyPlugin({
        patterns: [
          {
            context: "../../dist/apps/app/.next/server",
            to: "./app/[name][ext]",
            from: "../../../../../node_modules/@xmtp/user-preferences-bindings-wasm/dist/node",
            filter: (resourcePath) => resourcePath.endsWith(".wasm"),
          },
        ],
      }),
    );
    config.plugins.push(
      new CopyPlugin({
        patterns: [
          {
            context: "../../dist/apps/app/.next/server",
            to: "./chunks/[name][ext]",
            from: "../../../../../node_modules/@xmtp/user-preferences-bindings-wasm/dist/node",
            filter: (resourcePath) => resourcePath.endsWith(".wasm"),
          },
        ],
      }),
    );
  } else {
    config.plugins.push(
      new CopyPlugin({
        patterns: [
          {
            context: ".next/server",
            to: "./vendor-chunks/[name][ext]",
            from: "../../../../node_modules/@xmtp/user-preferences-bindings-wasm/dist/node",
            filter: (resourcePath) => resourcePath.endsWith(".wasm"),
          },
        ],
      }),
    );
  }
}
return config

With this adjustment both the development environment and the builds work fine, but then when I deployed the app to vercel I am getting the error below on async page (server components)

Error: ENOENT: no such file or directory, open '/var/task/dist/apps/app/.next/server/chunks/user_preferences_bindings_wasm_bg.wasm'
    at Object.openSync (node:fs:596:3)
    at Object.readFileSync (node:fs:464:35)
    at 29637 (/var/task/dist/apps/app/.next/server/chunks/2768.js:1:260264)
    at t (/var/task/dist/apps/app/.next/server/webpack-runtime.js:1:143)
    at 92174 (/var/task/dist/apps/app/.next/server/chunks/2768.js:1332:363665)
    at t (/var/task/dist/apps/app/.next/server/webpack-runtime.js:1:143)
    at 9775 (/var/task/dist/apps/app/.next/server/chunks/2768.js:1332:227208)
    at t (/var/task/dist/apps/app/.next/server/webpack-runtime.js:1:143)
    at 83770 (/var/task/dist/apps/app/.next/server/chunks/2174.js:3:6625)
    at t (/var/task/dist/apps/app/.next/server/webpack-runtime.js:1:143) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/var/task/dist/apps/app/.next/server/chunks/user_preferences_bindings_wasm_bg.wasm',
  digest: '1622321325'
}

Expected behavior

No response

Steps to reproduce the bug

No response

Tasks

No tasks being tracked yet.

Turns out it was caused by the Vercel Deployment Protection on preview routes (Vercel Authentication), when I deployed it to production the error is gone