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

feat: ssr.optimizeDeps #8917

Merged
merged 5 commits into from Jul 5, 2022
Merged

feat: ssr.optimizeDeps #8917

merged 5 commits into from Jul 5, 2022

Conversation

patak-dev
Copy link
Member

Description

Context:

Build SSR

We were using @rollup/plugin-commonjs, needed for noExternal CJS deps in Vite v2. For external deps nothing is needed. In v3 we replace the plugin with esbuild deps optimization. Implemented in:

Dev SSR

There is already interop, but it isn't perfect. Allowing users to optimize explicitly defined deps is a way to deal with problematic CJS deps in the SSR dev server. Implemented in:

Issue

In the PRs above we optimized every noExternal dep by default (during build we have the complete list, during dev only the explicit ones, but SSR dev interop is normally enough)

We also made optimizeDeps.include/exclude configure the way SSR optimization works. The problem is that the client env is quite different from the SSR env. @brillout, @benmccann, and others have been pushing hard for deps to be external by default (that we got done in v3).

We have conflicting requirements here, we have recommended people to use both include and external.

For the client, we need to optimize deps because:

  • Interop with CJS
  • Dependencies can end up sending too many files to the browser (lodash/es, etc), so we need to pre-bundle them

For SSR, we want to optimize deps only because:

  • They were set as noExternal and they are CJS

So for the browser, we want people to add things to include, but we don't want all these deps to be optimized during SSR. The best is to leave ESM deps untouched.

This PRs allows us to avoid the conflict by introducing a new ssr.optimizeDeps experimental option. So users can continue to use config.optimizeDeps for client only. esbuildOptions modifications are also specific to the client or ssr.

There are no overrides from optimizeDeps to ssr.optimizeDeps, both are independent for the reasons above.

ssr: {
  noExternal: [...],
  external: [...], <- by default, only useful to overwrite a noExternal pattern
  optimizeDeps: {
    exclude: [...], <- no external deps are optimized by default, use exclude to bail out
    esbuildOptions: { ... } <- custom config for SSR
  }
}

Fixes

The PR also takes into account exclude to define the external scheme started by @sodatea. Soda, I moved the plugin from config to the optimizer because we have the context needed (dev/build, ssr/non-ssr needed).

Refactor

  • getDepsOptimizer(config, { ssr }) => getDepsOptimizer(config, ssr)

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@netlify
Copy link

netlify bot commented Jul 4, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit 7e15cd7
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62c2ee55c70ac70008c99515

@patak-dev
Copy link
Member Author

One thing that is missing here is to avoid optimizing all deps when noExternal: true. We discussed with @bluwy that we should change the rule from:

  • noExternal -> optimize

to:

  • noExternal + CJS -> optimize

We don't need to optimize ESM dependencies in SSR

@patak-dev patak-dev added this to the 3.0 milestone Jul 4, 2022
@patak-dev patak-dev added p3-significant High priority enhancement (priority) feat: ssr feat: deps optimizer Esbuild Dependencies Optimization labels Jul 4, 2022
@patak-dev
Copy link
Member Author

It is linked in the comment, but for completeness here. Another option for the API is accepting a function:

optimizeDeps: ssr => ({
  ...
})

But not every option makes sense in ssr mode, and this will break the whole ecosystem that relies on adding entries to optimizeDeps.include/exclude.
I think the pattern of keeping flat objects and adding mirrored configs as needed to ssr is the best way forward.

@brillout
Copy link
Contributor

brillout commented Jul 4, 2022

What is the difference between:

  • noExternal: ['some-library'] + ssr.optimizeDeps.include: ['some-library'], and
  • noExternal: ['some-library'] + ssr.optimizeDeps.exclude: ['some-library']?

@patak-dev
Copy link
Member Author

  • noExternal: ['some-library'] + ssr.optimizeDeps.include: ['some-library'], and

'some-library' will be first pre-bundled with esbuild (together with the rest of the deps to optimize), then it will be bundled in the SSR build, as you have marked it as no external.

Note: same as just noExternal: ['some-library'] right now. Later we are thinking on changing the default to be: "included if CJS" in this case.

  • noExternal: ['some-library'] + ssr.optimizeDeps.exclude: ['some-library']?

'some-library' will be bundled in the SSR build, as you have marked it as no external. But it will not be pre-optimized with esbuild.

@brillout
Copy link
Contributor

brillout commented Jul 4, 2022

Is esbuild pre-bundling only about CJS -> ESM conversion? I guess it's only needed because Vite only understands ESM? (E.g. to be able to use es-module-lexer.)

Is it correct that Vite plugins are applied to noExternal SSR deps regardless of ssr.optimizeDeps.include/exclude?

VikePress (the docs framework used by https://vite-plugin-ssr.com and https://telefunc.com) needs to be added to ssr.noExtermal because it has CSS imports which Node.js cannot handle. So it's important that Vite 3 also prunes CSS imports of noExternal SSR deps like Vite 2 does. It's a similar use case than libraries that include .svelte files which also need to be added to ssr.noExternal. (Similar use case in the sense that the bottom line is: can Node.js handle the SSR dep? If no then add that dep to ssr.noExternal.)

@patak-dev
Copy link
Member Author

Yes, adding a dep to noExternal will make Vite process it. This doesn't change by the deps being optimized. And also yes, optimization during SSR is needed for CJS deps because we aren't going to use @rollup/plugin-commonjs anymore by default in v3.

@brillout
Copy link
Contributor

brillout commented Jul 4, 2022

Ok. This PR seems good to me.

The only thing I'm wondering is whether a user config ssr.optimizeDeps.include/exclude is needed and, instead, hardcoding noExternal + CJS <-> optimize would work.

@benmccann
Copy link
Collaborator

I was going to ask the same thing about whether the configuration is necessary. If it's CJS + external then excluding it will result in a breakage. If it's not CJS + external, is there a potential benefit?

@patak-dev
Copy link
Member Author

The only thing I'm wondering is whether a user config ssr.optimizeDeps.include/exclude is needed and, instead, hardcoding noExternal + CJS <-> optimize would work.

We need this, @cyco130 showed today a case in vavite where he needs to use noExternal + exclude to avoid the dep being optimized.
We also need include in case we discover that the SSR env during dev is faster when we optimize a dep like lodash/es (less ssrLoadModule calls?).
These are marked as experimental, and it is actually more work to don't provide them as the optimizer is now generic on non-ssr and ssr. So I think it is better to have them in SSR to see how useful they are for the ecosystem. If we find that some aren't needed, we can still remove them before taking the API out of experimental.

@patak-dev
Copy link
Member Author

patak-dev commented Jul 5, 2022

We talked with Evan and Anthony about the PR, and they both think this direction is good. Let's merge it and continue to build on top of it. I'll work on the heuristics change in a future PR.

@benmccann I agree with you about ssr.optimizeDeps options being unneeded if we get the heuristics right. Since we are going to launch with these, I think the escape hatches could prove useful. Lets gather experience from ecosystem usage

@patak-dev patak-dev merged commit f280dd9 into main Jul 5, 2022
@patak-dev patak-dev deleted the feat/ssr-optimize-deps-interaction branch July 5, 2022 07:09
@jiby-aurum
Copy link
Contributor

@patak-dev I was trying this out in a project, and I get the below error

npx vite build --ssr src/main/index.ts
vite v3.2.4 building SSR bundle for production...
transforming (6535) ../../node_modules/@aurumfit/af-baikonur-client/node_modules/node-fetch/src/request.jsUnexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/localRepositoryImplementation.ts"
(commonjs--resolver) resolveId "date-fns" "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/localRepositoryImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/env.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/env.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/stateMachineFactory.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/stateMachineFactory.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/date-fns.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/fp-ts.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/config/appConfig.ts"
(commonjs--resolver) resolveId "lodash" "/Users/jibyjose/Projects/training-app/apps/training-app/src/config/appConfig.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/models/machineState.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/models/machineState.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/ipc/ipcClientService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/guid.ts"
(commonjs--resolver) resolveId "cuid" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/guid.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/ipc/ipcClientService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/github/githubService.ts"
(commonjs--resolver) resolveId "octokit" "/Users/jibyjose/Projects/training-app/apps/training-app/src/github/githubService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/device.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/chartUtil.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/force.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/device.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/chartUtil.ts"
(commonjs--resolver) resolveId "monocle-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/force.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/xstate.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/exercise.ts"
(commonjs--resolver) resolveId "react-intl" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/exercise.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/lodash.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/stateMachineBootstrapper.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/stateMachineBootstrapper.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/baseBootstrapper.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/baseBootstrapper.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/cuid.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/context/message/index.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableWrappers.ts"
(commonjs--resolver) resolveId "react" "/Users/jibyjose/Projects/training-app/apps/training-app/src/context/message/index.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableWrappers.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableStateSubscription.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableStateSubscription.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/emitOnTimer.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/emitOnTimer.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/stateSubscription.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/stateSubscription.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/readyWatch.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/withPrevious.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/readyWatch.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/withPrevious.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/octokit.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/monocle-ts.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/logging/context.ts"
(commonjs--resolver) resolveId "react" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/logging/context.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/react-intl.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/test/framework/testRunnerImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/test/framework/testRunnerImplementation.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/rxjs_operators.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/rxjs.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/machineStateServiceImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/machineStateServiceImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/stateServiceSetupImplementation.ts"
(commonjs--resolver) resolveId "fp-ts/Json" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/stateServiceSetupImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatMaster.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatMaster.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/react.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/immer.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/motionApp.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/motionApp.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/helpers.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/helpers.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/machine.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/machine.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/transitionLogger.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/transitionLogger.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/fp-ts_Json.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/setup/setupBase.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/setup/setupBase.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/sensors/sensorSimulator.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/sensors/sensorSimulator.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ctrlx/CtrlxCore.js"
(commonjs--resolver) resolveId "atob" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ctrlx/CtrlxCore.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/sensors/sensorImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/sensors/sensorImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/simulatedMotion.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/simulatedMotion.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/observables.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/observables.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/wait.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/wait.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/serialization.ts"
(commonjs--resolver) resolveId "async-mutex" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/serialization.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeTimer.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeTimer.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeMachineState.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeMachineState.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/loadAppointments.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/loadAppointments.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/atob.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/async-mutex.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/baseWithCallback.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/baseWithCallback.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatSlaves.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatSlaves.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableEmergencyStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableEmergencyStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotionStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotionStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotorDiagnoseImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotorDiagnoseImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableRuntimeStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableRuntimeStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableTelemetryStateImplementation.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableTelemetryStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandSetTorque.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandSetTorque.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/workoutRepositoryImplementation.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/workoutRepositoryImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandExecutorBase.ts"
(commonjs--resolver) resolveId "async-mutex" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandExecutorBase.ts"
error during build:
Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/localRepositoryImplementation.ts"
(commonjs--resolver) resolveId "date-fns" "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/localRepositoryImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/env.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/env.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/stateMachineFactory.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/main/stateMachineFactory.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/date-fns.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/fp-ts.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/config/appConfig.ts"
(commonjs--resolver) resolveId "lodash" "/Users/jibyjose/Projects/training-app/apps/training-app/src/config/appConfig.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/models/machineState.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/models/machineState.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/ipc/ipcClientService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/guid.ts"
(commonjs--resolver) resolveId "cuid" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/guid.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/ipc/ipcClientService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/github/githubService.ts"
(commonjs--resolver) resolveId "octokit" "/Users/jibyjose/Projects/training-app/apps/training-app/src/github/githubService.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/device.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/chartUtil.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/force.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/device.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/chartUtil.ts"
(commonjs--resolver) resolveId "monocle-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/force.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/xstate.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/exercise.ts"
(commonjs--resolver) resolveId "react-intl" "/Users/jibyjose/Projects/training-app/apps/training-app/src/domain/exercise.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/lodash.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/stateMachineBootstrapper.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/stateMachineBootstrapper.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/baseBootstrapper.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/bootstrap/baseBootstrapper.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/cuid.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/context/message/index.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableWrappers.ts"
(commonjs--resolver) resolveId "react" "/Users/jibyjose/Projects/training-app/apps/training-app/src/context/message/index.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableWrappers.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableStateSubscription.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/observableStateSubscription.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/emitOnTimer.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/emitOnTimer.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/stateSubscription.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/stateSubscription.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/readyWatch.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/withPrevious.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/readyWatch.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/streams/withPrevious.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/octokit.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/monocle-ts.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/logging/context.ts"
(commonjs--resolver) resolveId "react" "/Users/jibyjose/Projects/training-app/apps/training-app/src/util/logging/context.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/react-intl.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/test/framework/testRunnerImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/test/framework/testRunnerImplementation.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/rxjs_operators.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/rxjs.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/machineStateServiceImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/machineStateServiceImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/stateServiceSetupImplementation.ts"
(commonjs--resolver) resolveId "fp-ts/Json" "/Users/jibyjose/Projects/training-app/apps/training-app/src/driver/services/stateServiceSetupImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatMaster.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatMaster.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/react.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/immer.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/motionApp.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/motionApp.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/helpers.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/helpers.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/machine.ts"
(commonjs--resolver) resolveId "xstate" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/machine.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/transitionLogger.ts"
(commonjs--resolver) resolveId "fp-ts" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/transitionLogger.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/fp-ts_Json.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/setup/setupBase.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/setup/setupBase.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/sensors/sensorSimulator.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/sensors/sensorSimulator.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ctrlx/CtrlxCore.js"
(commonjs--resolver) resolveId "atob" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ctrlx/CtrlxCore.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/sensors/sensorImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/sensors/sensorImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/simulatedMotion.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/simulatedMotion.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/observables.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/simulator/motors/observables.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/wait.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/wait.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/serialization.ts"
(commonjs--resolver) resolveId "async-mutex" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/util/serialization.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeTimer.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeTimer.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeMachineState.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/subscribeMachineState.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/loadAppointments.ts"
(commonjs--resolver) resolveId "rxjs/operators" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/loadAppointments.ts"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/atob.js"
(vite:optimized-deps-build) load "/Users/jibyjose/Projects/training-app/apps/training-app/node_modules/.vite/deps_build-build_ssr/async-mutex.js"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/baseWithCallback.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/apps/training-app/src/statemachine/services/baseWithCallback.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatSlaves.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/ethercat/ethercatSlaves.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableEmergencyStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableEmergencyStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotionStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotionStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotorDiagnoseImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableMotorDiagnoseImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableRuntimeStateImplementation.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableRuntimeStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableTelemetryStateImplementation.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/observables/observableTelemetryStateImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandSetTorque.ts"
(commonjs--resolver) resolveId "rxjs" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandSetTorque.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/workoutRepositoryImplementation.ts"
(commonjs--resolver) resolveId "immer" "/Users/jibyjose/Projects/training-app/apps/training-app/src/persistence/workout/workoutRepositoryImplementation.ts"
(vite:build-import-analysis) transform "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandExecutorBase.ts"
(commonjs--resolver) resolveId "async-mutex" "/Users/jibyjose/Projects/training-app/packages/machine-driver/src/motors/commands/commandExecutorBase.ts"
    at EventEmitter.handleEmptyEventLoop (file:///Users/jibyjose/Projects/training-app/node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:23121:20)
    at Object.onceWrapper (node:events:641:28)
    at EventEmitter.emit (node:events:527:28)
    at process.<anonymous> (file:///Users/jibyjose/Projects/training-app/node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:23115:55)
    at process.emit (node:events:539:35)

configuration is

import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import electron from 'vite-plugin-electron'
import { resolve } from 'path'

export default defineConfig(({ ssrBuild }) => ({
  base: './',
  plugins: ssrBuild ? [] : [react(), electron()],
  resolve: {
    alias: {
      '@assets': resolve('./src/assets'),
    },
  },
  test: {
    globals: true,
    threads: false,
  },
  ssr: {
    //noExternal: ssrBuild ? [/fp-ts/, /lodash/, /.*/] : [],
    noExternal: [/^(?!.*(electron))/],
    optimizeDeps: {
      disabled: false,
    },
  },
  build: {
    // commonjsOptions: {
    //   include: [],
    // },
    emptyOutDir: false,
    chunkSizeWarningLimit: 1024,
    outDir: 'build',
  },
  server: {
    port: 3000,
    strictPort: true,
  },
  preview: {
    port: 3000,
    strictPort: true,
  },
}))

any idea what it could be, or any pointers what to check ?

@patak-dev
Copy link
Member Author

@jiby-aurum not really without a proper repro. If you could craft a minimal reproduction, please create a new issue. It would be interesting if you try first without using electron, so the repro is easier to investigate.

@jiby-aurum
Copy link
Contributor

@patak-dev I will play a bit more around if I can figure it out, if not will try creating a minimal repro. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization feat: ssr p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants