Skip to content

Using __dirname to locate polar_wasm_api_bg.wasm causes problems in AWS nodejs lambda #1725

@sandborg71

Description

@sandborg71

When we try to use the oso library from an nodejs AWS lambda (using Serverless Framework) we get a problem with the path to the file polar_wasm_api_bg.wasm. In your library code the path to the polar_wasm_api_bg.wasm file is hardcoded to __dirname (see code snippet below). When the lambda executes this means the same dir as the lambda source and it means that we have to copy this wasm files to all source folders containing lambdas using oso, because of the way lambdas are built and executed. It would be very good if you for example by an optional environment variable or similar could have a bit more flexible way of telling the path to the wasm file. Or maybe there is an even better more standardized way of doing this wasm import in the code.

From your nodejs module node_modules/oso/dist/src/polar_wasm_api.js:

...
const path = require('path').join(__dirname, 'polar_wasm_api_bg.wasm');
const bytes = require('fs').readFileSync(path);

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
wasm = wasmInstance.exports;
module.exports.__wasm = wasm;
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions