vitejs / vite

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

Built project fails at runtime #12660

Closed luiz290788 closed 1 year ago

luiz290788 commented 1 year ago

Describe the bug

Everything works fine with with the development mode, but the preview is broken. It builds all right but I get this runtime error:

Uncaught TypeError: Object.defineProperty called on non-object
    at Function.defineProperty (<anonymous>)
    at sg (index-5c73fcc8.js:3921:19771)
    at al (index-5c73fcc8.js:3930:1901)
    at ct (index-5c73fcc8.js:3776:69724)
    at ov (index-5c73fcc8.js:33:126197)
    at sv (index-5c73fcc8.js:33:128666)
    at index-5c73fcc8.js:34:2836
    at Ir (index-5c73fcc8.js:37:2610)
    at Hi (index-5c73fcc8.js:37:2984)
    at index-5c73fcc8.js:47:3269

The only thing I made was to install a package called langium and import everything from the package and log.

I don't know if there is anything wrong with the package or vite.

Reproduction

https://stackblitz.com/edit/vitejs-vite-nfc7cf

Steps to reproduce

Run npm install then run npx vite preview.

Go to the browser and check the error in the console.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: ^4.2.1 => 4.2.1

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Tanimodori commented 1 year ago

Checkout https://stackblitz.com/edit/vitejs-vite-m8yvk7?file=vite.config.js

It seems langium having some circular commonjs dependencies. You need to set build.commonjsOptions.strictRequires to true. More info at https://github.com/rollup/plugins/tree/master/packages/commonjs#strictrequires

vite.config.js

import { defineConfig } from 'vite'

export default defineConfig({
  build: {
    commonjsOptions: {
      strictRequires: true
    }
  },
})
bluwy commented 1 year ago

Great find @Tanimodori. I don't think there's much we can do either, we're using a default that works for most projects, and I think it's acceptable that some deps doesn't work with it (especially that Vite is pushing ESM instead). I'll close this for now then.

luiz290788 commented 1 year ago

Thanks for all the help, that solves my problem!