Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

capi & vite dev mode: Top-level await is not available #77

Closed
karl-kallavus opened this issue Mar 6, 2023 · 4 comments
Closed

capi & vite dev mode: Top-level await is not available #77

karl-kallavus opened this issue Mar 6, 2023 · 4 comments

Comments

@karl-kallavus
Copy link
Contributor

karl-kallavus commented Mar 6, 2023

For "capi": "0.1.0-beta.26" there's an error after pnpm run dev

✘ [ERROR] Top-level await is not available in the configured target environment 
("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

    node_modules/.pnpm/capi@0.1.0-beta.26/node_modules/capi/esm/deps_2/raw.githubusercontent.com/paritytech/capi-crypto-wrappers/14289c5/lib.js:2:0:
      2 │ await wasm.instantiate();
        ╵ ~~~~~

Possible solutions:

@statictype
Copy link
Contributor

seems like the problem is in fact that Vite is not respecting the build target we set in the config

the plugin you suggested is only for when you don't want to set esnext as build target in Vite as mentioned in the docs:

Support all modern browsers of Vite's default target without need to set build.target to esnext.

Capi seems to use pretty recent targets, it should support top level await.

@karl-kallavus
Copy link
Contributor Author

karl-kallavus commented Mar 6, 2023

@statictype Top-level await expressions are only allowed when the module option is set to es2022

It seems like capi uses target: "ES2021"
https://github.com/paritytech/capi/blob/main/_tasks/dnt.ts#L21

I'll try to dnt capi using esnext/es2022/latest locally

Issue is related to dependency capi-crypto-wrappers

@karl-kallavus
Copy link
Contributor Author

Target: "ES2021" works fine as well.

So it's seems you're right @statictype

@karl-kallavus karl-kallavus removed their assignment Mar 6, 2023
@karl-kallavus karl-kallavus changed the title capi: Top-level await is not available capi & vite dev mode: Top-level await is not available Mar 6, 2023
@karl-kallavus
Copy link
Contributor Author

Pasting here a workaround from @tjjfvi just in case we need it in future

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [preact(), tsConfigPaths()],
  build: {
    target: "es2022",
  },
  optimizeDeps: {
    esbuildOptions: {
      target: "es2022",
    },
  },
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants