core icon indicating copy to clipboard operation
core copied to clipboard

[Bug report]: build with vite mode parallel with cause error

Open nonzzz opened this issue 2 years ago • 13 comments

Description

Background

Maybe it's look likes a bug. Refer nonzzz/vite-compression-plugin#18

I try to change vuepress it's vite build logic ( from parallel to serial. It works well

Form rollup/rollup#3506 i think we shouldn't parallel run vite build :)

Reproduction

https://github.com/u2sb/www.u2sb.com/tree/vite-compression-plugin

Used Package Manager

pnpm

System Info


$ vuepress build docs --clean-cache --clean-temp
✔ Cleaning temp - done in 20ms
✔ Cleaning cache - done in 2ms
✔ Initializing and preparing data - done in 3.45s
⠹ Compiling with vite
(!) Some chunks are larger than 1024 kBs after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✖ Compiling with vite - failed in 74.95s
Error: ENOENT: no such file or directory, open 'D:\githubDownLoad\www.u2sb.com\docs\.vuepress\.temp\.server\assets\app-77c74ba0.js'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

nonzzz avatar Feb 03 '23 10:02 nonzzz

I do think you need to provide detailed inforamation about what our problem is, at least the issue is now thrown at your plugin.

You may need to explain clearly:

  1. What's the central action of the issue part
  2. What we did to let this happen (our fault or just compatibility breaking
  3. Any possible solution

Mister-Hope avatar Feb 03 '23 10:02 Mister-Hope

@Mister-Hope Thanks for you feedback. I will update error message

nonzzz avatar Feb 03 '23 10:02 nonzzz

Sorry for the waitting. From the error info. I judged that the error occurred in the generatorBundle stage. Becasue currently. vuepress internal build logic is parallel. But it will casue rollup bundle context loose right hash assets file

nonzzz avatar Feb 03 '23 13:02 nonzzz

According


[clientOutput, serverOutput] = await Promise.all([
 viteBuild(clientConfig),
  viteBuild(serverConfig)
]);

Will emit an error

But with serial

image

nonzzz avatar Feb 03 '23 13:02 nonzzz

~~Sorry for the late reply, so what 's the actual problem of paralleling packaging one project with 2 rollup instance? I still need some further explanation.~~

~~It's fair to packing a project and outputting them at different places at same time.~~

Mister-Hope avatar Feb 07 '23 14:02 Mister-Hope

I got what the issue is.

Here we are generating 2 config:

https://github.com/vuepress/vuepress-next/blob/fd2e241235fc87c66ce59ba22c8e27521c594fbd/packages/bundler-vite/src/resolveViteConfig.ts

But we are sharing same plugin instance across client/server in build process. @meteorlxy

Mister-Hope avatar Feb 07 '23 14:02 Mister-Hope

Yes. You are right.It will cause concurrent.

nonzzz avatar Feb 07 '23 14:02 nonzzz

I think we should generator two difference app instance? Or build config?

nonzzz avatar Feb 07 '23 14:02 nonzzz

parallel build won't cause error ( My mistake

nonzzz avatar Feb 07 '23 14:02 nonzzz

I am not familiar with vite, but if you do think that 2 plugin instance is required to fix this, then a breaking change must be made at api, we shall use a callable function for bundler:

-   bundler: viteBundler({
-     // vite bundler config
-   })
+   bundler: () => viteBundler({
+     // vite bundler config
+   })

Mister-Hope avatar Feb 07 '23 14:02 Mister-Hope

Sounds bad. That will be a break change : (

nonzzz avatar Feb 07 '23 14:02 nonzzz

I look vuepress source code. I noticed https://github.com/vuepress/vuepress-next/blob/fd2e241235fc87c66ce59ba22c8e27521c594fbd/packages/bundler-vite/src/plugins/mainPlugin.ts#L93-L114

Currently, Us build config across client/server in build process. But will change the process of rollup generating hash. See rollup

By the way. rollup generateBundle is sequential : )

I think there two way to sovle.

  • Remove Promise.all ( Using serial.
  • Isolate two config list.

nonzzz avatar Feb 08 '23 03:02 nonzzz

Remove Promise.all ( Using serial.

This is definitely not our consideration, our build time is already long enough, and our primary goal is to improve speed

Mister-Hope avatar Mar 31 '23 05:03 Mister-Hope

Closing as this has been stale for a long time. Vite version and VuePress version has updated a lot.

Feel free to open a new issue with the latest version & context if it's still a problem

meteorlxy avatar Jun 19 '24 12:06 meteorlxy

I got what the issue is.

Here we are generating 2 config:

https://github.com/vuepress/vuepress-next/blob/fd2e241235fc87c66ce59ba22c8e27521c594fbd/packages/bundler-vite/src/resolveViteConfig.ts

But we are sharing same plugin instance across client/server in build process. @meteorlxy

I don't think this is should be resolved. A lot of plugins can not work in multiple instance.

Running successfully in multiple instance Means plugin cannot have any local state outside any hooks, But as plugins are designed callable, they should be allowed to have such things.

Mister-Hope avatar Jun 20 '24 08:06 Mister-Hope

I am not familiar with vite, but if you do think that 2 plugin instance is required to fix this, then a breaking change must be made at api, we shall use a callable function for bundler:

-   bundler: viteBundler({
-     // vite bundler config
-   })
+   bundler: () => viteBundler({
+     // vite bundler config
+   })

This should be a valid fix, but this is a breaking change. @meteorlxy

Mister-Hope avatar Jun 20 '24 08:06 Mister-Hope

Suggest remaining it open

Mister-Hope avatar Jun 20 '24 08:06 Mister-Hope