Issue with "AsyncLocalStorage" is not exported by "__vite-browser-external"

342 Views Asked by At

I'm developing an app in Nodejs and building it with vite. In my code I'm using "AsyncLocalStorage", but I get this error during build: "AsyncLocalStorage" is not exported by "__vite-browser-external", imported by [path name].

This is my code:

import { AsyncLocalStorage } from "node:async_hooks";

const asyncLocalStorage = new AsyncLocalStorage();
asyncLocalStorage.run(new Map(), () => {
  asyncLocalStorage.getStore()?.set("requestid", "45");
});

This is my vite.config.ts:

import { defineConfig } from "vite";

export default defineConfig({
  plugins: [],

  build: {
    rollupOptions: {
      input: "./index.js",
    },
  },
});


Everything is ok in develop mode and my app works properly, but not during the building. I appreciate it if you could help me. Thank you enter image description here

I also added rollup-plugin-node-polyfills and alias for 'async-hook' in vite config, but it seems it's not been added to vite yet.

0

There are 0 best solutions below