Instantiate wasm failed only in Vercel production

Things work well in local development, but failed in production.

Steps to reproduce:

  1. Install wasmoon by npm install wasmoon in a Nextjs 14 project.
  2. Create an engine according to its documentation.
const { LuaFactory } = require('wasmoon')

// Initialize a new lua environment factory
// You can pass the wasm location as the first argument, useful if you are using wasmoon on a web environment and want to host the file by yourself
const factory = new LuaFactory()
// Create a standalone lua environment from the factory
const lua = await factory.createEngine()
  1. Create a route file whether using page or app directory.
  2. Using the engine to execute some lua strings in the route handler.
  3. Deploy it to Vercel production.
  4. Request the api, you will see the error.

Wasmoon uses emscripten to generate the wasm file, and there’s a glue.js file to load and Instantiate the wasm module. In Vercel production environment, it couldn’t find the wasm file. I tried to provide a http resource of that wasm file(This is supported by wasmoon), its instantiation failed too.

I really appreciated if anyone could help with this.

Hi, @pureliumy!

Could you share any error logs? :pray:

Sure.

Aborted(RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'https:/unpkg.com/wasmoon/dist/glue.wasm'). Build with -sASSERTIONS for more info.)

And the request id if it helps

c4f9k-1723122359702-62b5a3ddcc90

I tried using outputFileTracingIncludes to include the wasm file in the output, but the deployment is always failed, then I added the outputFileTracingRoot option, and the deployment succeed, but the file was still not found in the deployment output, and still errors when execute the serverless function.

module.exports = {
  experimental: {
    outputFileTracingIncludes: {
      outputFileTracingRoot: path.join(__dirname, '../../'),
      '/api/mod/[id]': ['./apps/web/node_modules/wasmoon/dist/*.wasm'],
    },
  },
};

The error changed to this after I removed the custom wasm location.

Aborted(Error: ENOENT: no such file or directory, open '/var/task/node_modules/.pnpm/wasmoon@1.15.0/node_modules/wasmoon/dist/glue.wasm')

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.