Menci / vite-plugin-top-level-await

Transform code to support top-level await in normal browsers for Vite.
MIT License
273 stars 15 forks source link

Unexpected top-level statement "ExportDefaultExpression" in Rollup's output chunk. #22

Closed adimit closed 1 year ago

adimit commented 1 year ago

Hi. When I run yarn build in my project, I get the following error:

[vite-plugin-top-level-await] Unexpected top-level statement "ExportDefaultExpression" in Rollup's output chunk. Please open an issue at https://github.com/Menci/vite-plugin-top-level-await/issues.
error during build:
Error: Unexpected top-level statement "ExportDefaultExpression" in Rollup's output chunk. Please open an issue at https://github.com/Menci/vite-plugin-top-level-await/issues.
    at raiseUnexpectedNode (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/utils/error.js:6:11)
    at /path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/transform.js:36:49
    at Array.filter (<anonymous>)
    at transformModule (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/transform.js:28:35)
    at /path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/index.js:72:64
    at Array.map (<anonymous>)
    at Object.generateBundle (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/index.js:69:57)
    at async Bundle.generate (file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:16747:9)
    at async file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:24977:27
    at async catchUnfinishedHookActions (file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:24066:20)
    at async doBuild (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44518:22)
    at async build (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44347:16)
    at async CAC.<anonymous> (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/cli.js:808:9)"

It's reproducible with this commit and the following command:

git clone https://github.com/adimit/amazegen
cd amazegen
git checkout 83cabbe244
cd web/frontend
wasm-pack build --target bundler --release && yarn && yarn build

The config file looks like this:

import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig({
  plugins: [wasm(), topLevelAwait(), solidPlugin(), nodePolyfills()],
  server: {
    port: 3000,
    fs: {
      allow: [".", "../../pkg"],
    },
  },
});

My node version is 16.19.0

Menci commented 1 year ago

Thank you. I'll check it.

On Fri, Jan 27, 2023 at 07:47 Aleksandar Dimitrov @.***> wrote:

Hi. When I run yarn build in my project, I get the following error:

[vite-plugin-top-level-await] Unexpected top-level statement "ExportDefaultExpression" in Rollup's output chunk. Please open an issue at https://github.com/Menci/vite-plugin-top-level-await/issues. error during build: Error: Unexpected top-level statement "ExportDefaultExpression" in Rollup's output chunk. Please open an issue at https://github.com/Menci/vite-plugin-top-level-await/issues. at raiseUnexpectedNode (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/utils/error.js:6:11) at /path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/transform.js:36:49 at Array.filter () at transformModule (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/transform.js:28:35) at /path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/index.js:72:64 at Array.map () at Object.generateBundle (/path-to-source/src/maze/web/frontend/node_modules/vite-plugin-top-level-await/dist/index.js:69:57) at async Bundle.generate (file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:16747:9) at async file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:24977:27 at async catchUnfinishedHookActions (file:///path-to-source/src/maze/web/frontend/node_modules/rollup/dist/es/shared/rollup.js:24066:20) at async doBuild (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44518:22) at async build (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44347:16) at async CAC. (file:///path-to-source/src/maze/web/frontend/node_modules/vite/dist/node/cli.js:808:9)"

It's reproducible with this commit https://github.com/adimit/amazegen/tree/83cabbe244a124aab2c88515f2dfcd41905c1739 and the following command:

cd web/frontend wasm-pack build --target bundler --release && yarn && yarn build

The config file looks like this:

import { defineConfig } from "vite"; import solidPlugin from "vite-plugin-solid"; import wasm from "vite-plugin-wasm"; import topLevelAwait from "vite-plugin-top-level-await"; import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig({ plugins: [wasm(), topLevelAwait(), solidPlugin(), nodePolyfills()], server: { port: 3000, fs: { allow: [".", "../../pkg"], }, }, });

— Reply to this email directly, view it on GitHub https://github.com/Menci/vite-plugin-top-level-await/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWRBAY5JINGICKMI3MJYWLWUMEJ3ANCNFSM6AAAAAAUIC4AJQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Menci commented 1 year ago

Fixed in https://github.com/Menci/vite-plugin-top-level-await/commit/ec81ad77a73e58c1b665b4a7ec77a7f8813d5227 and released in v1.2.3.

adimit commented 1 year ago

@Menci, thank you very much. That was amazingly quick. I can confirm it worked.

NautHnil commented 11 months ago

@Menci I got an error related to "Rollup". Please check help me.

error during build:
Error: Cannot find module 'rollup'
Require stack:
- /node_modules/vite-plugin-top-level-await/dist/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/node_modules/vite-plugin-top-level-await/dist/index.js:30:18)
    at Module._compile (node:internal/modules/cjs/loader:[110](https://gitlab.com/-/jobs/5739256849#L110)3:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:[115](https://gitlab.com/-/jobs/5739256849#L115)5:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)