Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running vite dev doesn't exit with an error when there is a problem in the dependency optimisation step (esbuild) #19364

Open
7 tasks done
mansona opened this issue Feb 5, 2025 · 1 comment

Comments

@mansona
Copy link
Contributor

mansona commented Feb 5, 2025

Describe the bug

Currently in the Ember project we are using the command vite optimize to verify that all the dependencies are being optimised correctly (see this test file if you're curious). With the recent deprecation of the vite optimize command #19348 we need a way to be able to verify the dependency optimisation step passes without error in our CI.

We can't rely on vite dev for this information because an esbuild plugin fails for any reason that dependency just gets externalised and will be re-loaded once the Vite dev server starts. You can see that behaviour in the linked reproduction.

Even if we don't make vite dev always fail for people if esbuild fails (maybe this is a default that might need to wait for a major?) we would love the ability to pass an arg that would opt-in to this behaviour e.g. vite dev --brittle or something

Reproduction

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

Steps to reproduce

  • run npm install
  • run npx vite dev
  • observe that the esbuild fails and logs in the terminal
  • observe that the vite dev server succeeds and serves the app

System Info

This is just taken from the stackblitz link above: 

  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: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^6.0.0 => 6.0.11

Used Package Manager

npm

Logs

VITE v6.0.11 ready in 1069 ms

➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
Error: Failed to scan for dependencies from entries:
/home/projects/vitejs-vite-tb94xq8d/index.html

✘ [ERROR] oops [plugin example]

node_modules/esbuild/lib/main.js:1216:27:
  1216 │         let result = await callback({
       ╵                            ^

at eval (file:///home/projects/vitejs-vite-tb94xq8d/node_modules/.vite-temp/vite.config.js.timestamp-1738762350011-5946a081b8f51.mjs:21:17)
at requestCallbacks.on-resolve (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1216:28)
at handleRequest (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:637:17)
at handleIncomingPacket (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:662:7)
at Socket.readFromStdout (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:590:7)
at Socket.emit (node:events:30:10899)
at addChunk (node:internal/streams/readable:225:3685)
at readableAddChunk (node:internal/streams/readable:225:3393)
at Readable.push (node:internal/streams/readable:225:4971)
at _0x1e0a15.onStreamRead (node:internal/stream_base_commons:211:2596)

This error came from the "onResolve" callback registered here:

node_modules/esbuild/lib/main.js:1140:20:
  1140 │       let promise = setup({
       ╵                     ^

at setup (file:///home/projects/vitejs-vite-tb94xq8d/node_modules/.vite-temp/vite.config.js.timestamp-1738762350011-5946a081b8f51.mjs:19:13)
at handlePlugins (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1140:21)
at buildOrContextImpl (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:863:5)
at Object.buildOrContext (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:689:5)
at eval (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1844:68)
at <anonymous> (https://vitejsvitetb94xq8d-qpd2.w-credentialless-staticblitz.com/blitz.d20a0a75.js:40:25239)
at new Promise (https://vitejsvitetb94xq8d-qpd2.w-credentialless-staticblitz.com/blitz.d20a0a75.js:40:25210)
at Object.context (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1844:27)

The plugin "example" was triggered by this import

src/main.js:4:29:
  4 │ import { setupCounter } from './counter.js';
    ╵                              ~~~~~~~~~~~~~~


at failureErrorWithLog (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1466:15)
at eval (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:935:25)
at runOnEndCallbacks (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:1306:45)
at buildResponseToResult (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:933:7)
at eval (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:945:9)
at <anonymous> (https://vitejsvitetb94xq8d-qpd2.w-credentialless-staticblitz.com/blitz.d20a0a75.js:40:25239)
at new Promise (https://vitejsvitetb94xq8d-qpd2.w-credentialless-staticblitz.com/blitz.d20a0a75.js:40:25210)
at requestCallbacks.on-end (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:944:54)
at handleRequest (/home/projects/vitejs-vite-tb94xq8d/node_modules/esbuild/lib/main.js:637:17)

Validations

@sapphi-red
Copy link
Member

How about using this plugin?

function exitIfError() {
  return {
    name: 'error',
    setup(build) {
      build.onEnd((result) => {
        if (result.errors.length > 0) {
          console.log(new AggregateError(result.errors));
          process.exit(1);
        }
      });
    },
  };
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants