second-state / wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
Apache License 2.0
477 stars 59 forks source link

The symbol "Stats" has already been declared #122

Open lastmjs opened 8 months ago

lastmjs commented 8 months ago

Hi, I'm incorporating wasmedge-quickjs into my own project that doesn't use wasmedge as a runtime, and I'm trying to get the fs module to work.

I get this error when I try to import it with my bundling process: TypeScript error: The symbol "Stats" has already been declared

It seems pretty obvious why this is the case, see here: https://github.com/second-state/wasmedge-quickjs/blob/main/modules/internal/fs.js#L2

Stats is both imported and there is a local class called Stats as well. This is not allowed.

lastmjs commented 8 months ago

This seems to be happening with various files, I'll put them in here as comments:

TypeScript error: The symbol "debuglog" has already been declared

https://github.com/second-state/wasmedge-quickjs/blob/main/modules/util.js#L2

lastmjs commented 8 months ago

TypeScript error: The symbol "promisify" has already been declared

https://github.com/second-state/wasmedge-quickjs/blob/main/modules/util.js#L1

lastmjs commented 8 months ago

TypeScript error: The symbol "deprecate" has already been declared

https://github.com/second-state/wasmedge-quickjs/blob/main/modules/util.js#L1

juntao commented 8 months ago

Running this project outside of WasmEdge could have a lot of WASI challenges. WASI preview 1 simply does not define a lot of host functions required in nodejs.

lastmjs commented 7 months ago

These are just basic JS issues.

Stats is both imported and there is a local class called Stats as well. This is not allowed.

The build process you all have seems to ignore the issues for some reason. You'll notice in the OP that I point out the issue directly, you can't import something with the same name as a class in the same module/file.

These errors are repeated a couple times.

lastmjs commented 7 months ago

This is similar to what's happening various times in the wasmedge-quickjs codebase: https://www.typescriptlang.org/play?ssl=1&ssc=10&pln=1&pc=22#code/JYWwDg9gTgLgBAbzlApgQwCYDFgBsUDKAngHYDGcAvnAGZQQhwDkNAzkwNwBQXZuarVsnTY8hUhQSUgA

L-jasmine commented 7 months ago

I'm very sorry, I will fix them as soon as possible.

L-jasmine commented 7 months ago

May I ask how you got these warnings? Are you using TypeScript, or did you simply import these problematic modules?

lastmjs commented 7 months ago

We are using TypeScript yes, but specifically esbuild as our bundler. Our Wasm binaries must then run in Node's Wasm environment and the Internet Computer's Wasmtime environment.

Here's the most important part of our build process: https://github.com/demergent-labs/azle/blob/main/src/compiler/compile_typescript_code.ts#L56