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

Fix with-webassembly example and convert to Typescript #43677

Merged
merged 4 commits into from Dec 12, 2022

Conversation

maxproske
Copy link
Contributor

@maxproske maxproske commented Dec 3, 2022

// Before
config.output.webassemblyModuleFilename = 'static/wasm/[modulehash].wasm'

// After
config.output.webassemblyModuleFilename =
  isServer && !dev
    ? '../static/wasm/[modulehash].wasm'
    : 'static/wasm/[modulehash].wasm'
> Build error occurred
Error: Export encountered errors on following paths:
        /
    at /Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/export/index.js:408:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Span.traceAsyncFn (/Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/trace/trace.js:79:20)
    at async /Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/build/index.js:1342:21
    at async Span.traceAsyncFn (/Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/trace/trace.js:79:20)
    at async /Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/build/index.js:1202:17
    at async Span.traceAsyncFn (/Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/trace/trace.js:79:20)
    at async Object.build [as default] (/Users/max/dev/next.js/examples/with-webassembly/node_modules/next/dist/build/index.js:65:29)
 ELIFECYCLE  Command failed with exit code 1.

Documentation / Examples

  • Make sure the linting passes by running pnpm build && pnpm lint
  • The "examples guidelines" are followed from our contributing doc

@ijjk ijjk added the example bug Issue was opened via the example bug report template. label Dec 3, 2022
Comment on lines +5 to +8
const module$ = WebAssembly.instantiate(addWasm)

export default async function handler() {
const instance = (await module$) as any
Copy link
Contributor Author

@maxproske maxproske Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const module$ = WebAssembly.instantiate(addWasm)
export default async function handler() {
const instance = (await module$) as any
export default async function handler() {
const instance = (await WebAssembly.instantiate(addWasm)) as any

I'm not aware what the advantage of initiating the wasm module$ outside the API handler like this is. But I've left it as-is, unless you want to commit this suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instantiating outside of the handler allows re-using the same instance which is a bit more performant so I think it's good we leave that as is.

@ijjk ijjk merged commit bfd96ac into vercel:canary Dec 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
example bug Issue was opened via the example bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants