vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
69.25k stars 6.26k forks source link

vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function #18850

Open zhangHongEn opened 1 week ago

zhangHongEn commented 1 week ago

Describe the bug

Everything works fine with Vite 5.

Top-level await in node_modules. https://github.com/module-federation/vite/issues/201

Reproduction

https://github.com/zhangHongEn/vite-mf-bug

Steps to reproduce

npm install && npm run build

System Info

System:
    OS: macOS 14.3.1
    CPU: (8) arm64 Apple M2
    Memory: 2.71 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
    pnpm: 9.6.0 - ~/.nvm/versions/node/v18.20.2/bin/pnpm
  Browsers:
    Safari: 17.3.1

Used Package Manager

npm

Logs

> vite-project@0.0.0 build
> vite build

vite v6.0.1 building for production...
✓ 9 modules transformed.
x Build failed in 104ms
error during build:
[commonjs--resolver] node_modules/.pnpm/test-top-level-await@1.0.0/node_modules/test-top-level-await/a.js (1:6): await isn't allowed in non-async function
file: /Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/test-top-level-await@1.0.0/node_modules/test-top-level-await/a.js:1:6

1: await 1
         ^
2: exports = {}

    at getRollupError (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at ParseError.initialise (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/node-entry.js:13286:28)
    at convertNode (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/node-entry.js:14997:10)
    at convertProgram (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/node-entry.js:14240:12)
    at Module.setSource (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/node-entry.js:15983:24)
    at async ModuleLoader.addModuleSource (file:///Users/zhanghongen/Desktop/zwork/open-code/testdir/vite-project/node_modules/.pnpm/rollup@4.28.0/node_modules/rollup/dist/es/shared/node-entry.js:19879:13)

Validations

sapphi-red commented 1 week ago

It doesn't work with Vite v5 too. https://stackblitz.com/edit/github-441yb3?file=package.json&terminal=build

I don't think this should work because top-level await cannot be used in CJS (https://github.com/nodejs/node/issues/21267).

zhangHongEn commented 1 week ago

Have you tried the build mode?

---- Replied Message ---- | From | @.> | | Date | 12/02/2024 09:28 | | To | vitejs/vite @.> | | Cc | zhn @.>, Author @.> | | Subject | Re: [vitejs/vite] vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function (Issue #18850) |

It doesn't work with Vite v5 too. https://stackblitz.com/edit/github-441yb3?file=package.json&terminal=build

I don't think this should work because top-level await cannot be used in CJS (nodejs/node#21267).

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sapphi-red commented 1 week ago

Yes, I have.

zhangHongEn commented 1 week ago

I don't have a computer with me right now. I'll check it tonight

---- Replied Message ---- | From | @.> | | Date | 12/02/2024 09:33 | | To | vitejs/vite @.> | | Cc | zhn @.>, Author @.> | | Subject | Re: [vitejs/vite] vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function (Issue #18850) |

Yes, I have.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>