Skip to content

Vite 3 - npm package as rollupOptions.input fails when package is unused by other inputs #8750

Closed
@bholmesdev

Description

Describe the bug

I am running a Vite 3 production build via the JavaScript API, and I'm using an npm package within my build.rollupOptions.input array. This succeeds for npm packages used by other files in the input array. However, if that npm package is unused by other inputs, the build will fail!

Example:

import { build } from 'vite';
(async () => {
  await build({
    build: {
      rollupOptions: {
        input: [
          // Fails when resolving the npm package alone
          'is-odd',
          // ...but succeeds if that npm package is used by another input.
          // Uncomment this line to fix the error 👇
          //'src/test-module.js',
        ],
      },
    },
  });
})();

Interestingly, I was unable to replicate in Stackblitz. See the link below for a step-by-step reproduction when running locally!

Reproduction

https://github.com/bholmesdev/vite-3-bug-build-npm-package

System Info

System:
    OS: macOS 12.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 84.06 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.115
    Firefox: 101.0.1
    Safari: 15.3
  npmPackages:
    vite: 3.0.0-beta.1 => 3.0.0-beta.1

Used Package Manager

npm

Logs

vite v3.0.0-beta.1 building for production...
Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:optimized-deps-build) load "/Users/benholmes/Sandbox/vite-server-build-simulaneously/node_modules/.vite/deps_build-dist/is-odd.js"
file:///Users/benholmes/Sandbox/vite-server-build-simulaneously/node_modules/rollup/dist/es/shared/rollup.js:23048
reject(new Error(Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n +
^

Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:optimized-deps-build) load "/Users/benholmes/Sandbox/vite-server-build-simulaneously/node_modules/.vite/deps_build-dist/is-odd.js"
at EventEmitter.handleEmptyEventLoop (file:///Users/benholmes/Sandbox/vite-server-build-simulaneously/node_modules/rollup/dist/es/shared/rollup.js:23048:20)
at Object.onceWrapper (node:events:639:28)
at EventEmitter.emit (node:events:520:28)
at process. (file:///Users/benholmes/Sandbox/vite-server-build-simulaneously/node_modules/rollup/dist/es/shared/rollup.js:23042:55)
at process.emit (node:events:520:28)

Validations

Activity

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

Metadata

Assignees

No one assigned

    Labels

    feat: deps optimizerEsbuild Dependencies Optimizationp3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions