Skip to content

photon compatibility #19

@mukundshah

Description

@mukundshah

Environment

  • Operating System: Darwin
  • Node Version: v21.6.2
  • Nitro Version: 2.9.1
  • Package Manager: [email protected]

Reproduction

N/A

Describe the bug

If a wasm contains imports from relative path, the module name will have foreign unintended characters.

For context, photon-rs has some imports from relative path, and using it causes the following error:

(inject plugin) rollup-plugin-inject: failed to parse ~/Developer/play/nitro-wasm/routes/wasm/photon_rs_bg.wasm. Consider restricting the plugin to particular files via options.include
routes/wasm/photon_rs_bg.wasm (6:2) Error when using sourcemap for reporting an error: Can't resolve original location of error.

[nitro 6:22:17 PM]  ERROR  RollupError: Unexpected token .. Expected identifier, string literal, numeric literal or [ for the computed key (Note that you need plugins to import files that are not JavaScript)


4: import { base64ToUint8Array } from "unwasm:helpers";
5: const _imports = {
6:   ./photon_rs_bg.js: {
     ^
7:     __wbindgen_object_drop_ref: () => { throw new Error("./photon_rs_bg.js.__wbindgen_object_drop_ref is not provid...

This issue is resolved when moduleName is json-stringified at L180 in

code += `\n ${moduleName}: {`;
for (const name of importNames) {
code += pkgImport
? `\n ${name}: _imports_${moduleName}.${name},\n`
: `\n ${name}: () => { throw new Error("\`${moduleName}.${name}\` is not provided!")},\n`;
}
code += " },\n";

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions