vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.17k stars 6.04k forks source link

Vite Plugin Legacy unable to build BigInt #17392

Closed jwcooper closed 3 months ago

jwcooper commented 3 months ago

Describe the bug

Using defaults, vite plugin legacy errors out on a statement such as console.log(123n)

console.log(BigInt(123)) works just fine.

Reproduction

https://github.com/jwcooper/vite-bigint

Steps to reproduce

Run npm install followed by npm run build

System Info

System:
    OS: Linux 6.8 Fedora Linux 40 (Workstation Edition)
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 15.76 GB / 31.25 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 20.11.0 - ~/.asdf/installs/nodejs/20.11.0/bin/node
    Yarn: 1.22.21 - ~/.asdf/installs/nodejs/20.11.0/bin/yarn
    npm: 10.4.0 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 127.0.6510.4
  npmPackages:
    @vitejs/plugin-legacy: ^5.4.1 => 5.4.1 
    @vitejs/plugin-vue: ^5.0.4 => 5.0.5 
    vite: ^5.2.0 => 5.2.12

Used Package Manager

npm

Logs

> bigint@0.0.0 build                                                                                                                                                      
> vite build                                                                                                                                                              

vite v5.2.12 building for production...                                                                                                                                   
✓ 16 modules transformed.                                                                                                                                                 
dist/assets/index-legacy-4yahLsja.js      67.23 kB │ gzip: 24.37 kB                                                                                                       
dist/assets/polyfills-legacy-Lh3Ygw8X.js  79.60 kB │ gzip: 32.16 kB                                                                                                       
x Build failed in 3.94s                                                                                                                                                   
error during build:                                                                                                                                                       
[vite:esbuild-transpile] Transform failed with 1 error:                                                                                                                   
assets/index-!~{001}~.js:5726:12: ERROR: Big integer literals are not available in the configured target environment ("chrome64", "edge79", "es2020", "firefox67", "safari
12" + 2 overrides)                                                                                                                                                        

Big integer literals are not available in the configured target environment ("chrome64", "edge79", "es2020", "firefox67", "safari12" + 2 overrides)                       
5724|  const App = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-d6420450"]]);                                                                                
5725|                                                                                                                                                                     
5726|  console.log(123n);                                                                                                                                                 
   |              ^                                                                                                                                                       
5727|  
5728|  createApp(App).mount('#app');

    at failureErrorWithLog (/home/jwcooper/dev/tmp/bigint/node_modules/esbuild/lib/main.js:1651:15)
    at /home/jwcooper/dev/tmp/bigint/node_modules/esbuild/lib/main.js:849:29
    at responseCallbacks.<computed> (/home/jwcooper/dev/tmp/bigint/node_modules/esbuild/lib/main.js:704:9)
    at handleIncomingPacket (/home/jwcooper/dev/tmp/bigint/node_modules/esbuild/lib/main.js:764:9)
    at Socket.readFromStdout (/home/jwcooper/dev/tmp/bigint/node_modules/esbuild/lib/main.js:680:7)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Validations

btea commented 3 months ago

It looks like esbuild reported an error. You may refer to this link. https://github.com/evanw/esbuild/issues/732

bluwy commented 3 months ago

Yeah I think this is expected. It's not possible to downlevel BigInt to be used in older browsers that don't support it. However, if you want to get the build passing you can configure this:

  esbuild: {
    supported: {
      bigint: true
    }
  }

So that esbuild will assume that bigint will be supported. However your site will not work when it runs the file that contains the BigInt syntax.