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

Cannot find namespace 'WebAssembly' #2388

Closed
doteric opened this issue Jul 13, 2022 · 5 comments · Fixed by #3679
Closed

Cannot find namespace 'WebAssembly' #2388

doteric opened this issue Jul 13, 2022 · 5 comments · Fixed by #3679

Comments

@doteric
Copy link

doteric commented Jul 13, 2022

During the compilation using tsc with the esbuild API I encountered following error:

node_modules/esbuild/lib/main.d.ts:584:16 - error TS2503: Cannot find namespace 'WebAssembly'.

I had to skipLibCheck in TypeScript so that I can compile without any errors.

image

@evanw
Copy link
Owner

evanw commented Jul 13, 2022

It's defined by TypeScript itself in typescript/lib/lib.dom.d.ts:

declare namespace WebAssembly {
    interface Module {
    }

    var Module: {
        prototype: Module;
        new(bytes: BufferSource): Module;
        customSections(moduleObject: Module, sectionName: string): ArrayBuffer[];
        exports(moduleObject: Module): ModuleExportDescriptor[];
        imports(moduleObject: Module): ModuleImportDescriptor[];
    };

    ...
}

Maybe you're using an old version of TypeScript?

@doteric
Copy link
Author

doteric commented Jul 13, 2022

Hey @evanw
I use typescript 4.7.3. I see that the WebAssembly namespace is there in node_modules\typescript\lib\lib.dom.d.ts indeed, but TypeScript doesn't pick that up. 🤔

Here is the project that the problem exists if you'd like to check yourself: https://github.com/doteric/funpack

@hyrious
Copy link

hyrious commented Jul 14, 2022

This is because you have "lib": ["es2021"], while WebAssembly is in "dom".

The simplest solution would be changing your tsconfig to "lib": ["es2021", "dom"], however it may be wrong because your code are not supposed to be run in the browser.

Another solution I was thinking about is installing @types/node since there's also a WebAssembly in node environment, however I looked into that package and unfortunately I didn't find the definition. Some references: DefinitelyTyped/DefinitelyTyped#48648 DefinitelyTyped/DefinitelyTyped#57055 It looks like they are facing the problem of global type conflicting with the built-in ones.

Another choice would be esbuild trying to loose the type constraints, providing a minimal WebAssembly.Module that mimics the one in the "dom", for example:

interface WebAssemblyModule {}
...
wasmModule?: WebAssemblyModule

@doteric
Copy link
Author

doteric commented Jul 14, 2022

Thanks for looking into this @hyrious
Pretty interesting, and yeah dom wouldn't really fit into the package as it's only used on node.
For now I'm fine with going with skipLibCheck, but just reported this issue for the awareness 😄

@evanw
Copy link
Owner

evanw commented Jul 14, 2022

Ok. I'm going to close this since the dom library is how TypeScript has chosen to ship type annotations for the WebAssembly API. This is a problem with TypeScript, not with esbuild. See also microsoft/TypeScript#47381 and microsoft/TypeScript-DOM-lib-generator#826.

@evanw evanw closed this as completed Jul 14, 2022
tennox added a commit to tennox/vite-plugin-logseq that referenced this issue Dec 6, 2022
xiehan added a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 21, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 21, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 24, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 25, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 26, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 27, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Jul 31, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 1, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 7, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 8, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 9, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 11, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 15, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 16, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 17, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 19, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 21, 2023
See evanw/esbuild#2388 for why this fix was necessary.
team-tf-cdk pushed a commit to hashicorp/cdktf-aws-cdk that referenced this issue Aug 23, 2023
See evanw/esbuild#2388 for why this fix was necessary.
agladysh added a commit to agladysh/esbuild-plugin-nearley that referenced this issue Aug 28, 2023
agladysh added a commit to agladysh/esbuild-plugin-nearley that referenced this issue Aug 28, 2023
juice49 added a commit to juice49/groq-tools-raycast that referenced this issue Sep 18, 2023
remcohaszing added a commit to remcohaszing/esbuild that referenced this issue Mar 5, 2024
Currently the TypeScript types for esbuild depend on the DOM types.
However, esbuild itself does not depend on the DOM.

This change uses type augmentation to make the type error go away, while
keeping backwards support for use with the DOM types.

Closes evanw#2388
ccharly added a commit to MetaMask/accounts-chain-api that referenced this issue Apr 24, 2024
ccharly added a commit to MetaMask/accounts-chain-api that referenced this issue Apr 24, 2024
sibbng added a commit to sibbng/esbuild that referenced this issue Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants