Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated JavaScript filenames need to use kebab-case everywhere #98

Open
Michael-F-Bryan opened this issue Nov 22, 2022 · 0 comments · May be fixed by #115
Open

Generated JavaScript filenames need to use kebab-case everywhere #98

Michael-F-Bryan opened this issue Nov 22, 2022 · 0 comments · May be fixed by #115
Labels
category: bug Something isn't working

Comments

@Michael-F-Bryan
Copy link
Contributor

In today's retro, we were playing around with the bindings for dynamite-bud/hello_world (note the _) and ran into an error with the generated bindings.

The JavaScript code:

// index.mjs

import { bindings } from "@dynamite-bud/hello_world";

async function main() {
	const wasm = await bindings.hello_world();
	console.log(wasm.greet("World"));
}

main();

The error:

$ node ./index.mjs
node:internal/modules/cjs/loader:995
  const err = new Error(message);
              ^

Error: Cannot find module './hello_world/hello_world.js'
Require stack:
- /tmp/node_modules/@dynamite-bud/hello_world/src/bindings/index.js
- /tmp/node_modules/@dynamite-bud/hello_world/src/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/tmp/node_modules/@dynamite-bud/hello_world/src/bindings/index.js:2:37)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/tmp/node_modules/@dynamite-bud/hello_world/src/bindings/index.js',
    '/tmp/node_modules/@dynamite-bud/hello_world/src/index.js'
  ]
}

Node.js v19.0.0

The generated files:

$ tree ./node_modules/@dynamite-bud/hello_world
./node_modules/@dynamite-bud/hello_world
├── package.json
└── src
    ├── bindings
    │   ├── hello_world
    │   │   ├── hello-world.d.ts
    │   │   ├── hello-world.js
    │   │   ├── hello_world.wasm
    │   │   └── intrinsics.js
    │   ├── index.d.ts
    │   └── index.js
    ├── index.d.ts
    └── index.js

3 directories, 9 files

If you look at the generated src/bindings/index.js, we see that it assumes the file generated by wai-bindgen is called hello_world.js (same as the package name) instead of hello-world.js.

$ head ./node_modules/@dynamite-bud/hello_world/src/bindings/index.js
const fs = require("fs/promises");
const { HelloWorld: _HelloWorld } = require("./hello_world/hello_world.js");
...
@Michael-F-Bryan Michael-F-Bryan added the category: bug Something isn't working label Nov 22, 2022
Michael-F-Bryan pushed a commit that referenced this issue Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant