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

Getting different hashes when running build on the same files #13071

Closed
7 tasks done
dmix opened this issue May 2, 2023 · 11 comments
Closed
7 tasks done

Getting different hashes when running build on the same files #13071

dmix opened this issue May 2, 2023 · 11 comments

Comments

@dmix
Copy link

dmix commented May 2, 2023

Describe the bug

We're trying to deploy an upgrade from Vite 2.9 -> 4 and we're having a problem where 2 servers are getting different hashes.

I reproduced this locally, just by running build, I've run it about 30 times in a row and it always outputs one of two files:

yarn run vite build --mode production

This outputs either:

../../public/vite/assets/application-8f133cfb.js
../../public/vite/assets/application-06ecfed2.js

The diff between the two outputted files:

<   */const as=typeof window<"u";function ane(e){return e.__esModule||e[Symbol.toStringTag]==="Module"}const sn=Object.assign;function Lp(e,t){const n={};for(const r in t){const a=t[r];n[r]=po(a)?a.map(e):e(a)}return n}const Ai=()=>{},po=Array.isArray,lne=/\/$/,sne=e=>e.replace(lne,"");function Ip(e,t,n="/"){let r,a={},s="",i="";const c=t.indexOf("#");let d=t.indexOf("?");return c<d&&c>=0&&(d=-1),d>-1&&(r=t.slice(0,d),s=t.slice(d+1,c>-1?c:t.length),a=e(s)),c>-1&&(r=r||t.slice(0,c),i=t.slice(c,t.length)),r=d---
>   */const as=typeof window<"u";function ane(e){return e.__esModule||e[Symbol.toStringTag]==="Module"}const sn=Object.assign;function Lp(e,t){const n={};for(const r in t){const a=t[r];n[r]=po(a)?a.map(e):e(a)}return n}const Ai=()=>{},po=Array.isArray,lne=/\/$/,sne=e=>e.replace(lne,"");function Ip(e,t,n="/"){let r,a={},s="",i="";const c=t.indexOf("#");let d=t.indexOf("?");return c<d&&c>=0&&(d=-1),d>-1&&(r=t.slice(0,d),s=t.slice(d+1,c>-1?c:t.length),a=e(s)),c>-1&&(r=r||t.slice(0,c),i=t.slice(c,t.length)),r=d124c124

Any ideas on where this difference is being introduced?

Note: This is on my work production system with hundreds of files so it would be difficult to share a reproduceable build here. If that is 100% necessary I can delete this issue.

System Info

Vite configs:

https://gist.github.com/dmix/4059efd362348c6654ea29a111bdd081

Rails 7 + Vue 3 + Vite 4. Happens on both ubuntu and macos.


 System:
    OS: macOS 13.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 18.07 GB / 64.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 18.15.0 - /opt/homebrew/opt/node@18/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.0 - /opt/homebrew/bin/npm
    Watchman: 2023.02.27.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 107.0.5304.62
    Chrome Canary: 111.0.5559.0
    Firefox: 113.0
    Firefox Nightly: 111.0a1
    Safari: 16.4
  npmPackages:
    @vitejs/plugin-vue: 4.1.0 => 4.1.0 
    @vitejs/plugin-vue-jsx: 3.0.0 => 3.0.0 
    vite: 4.2.0 => 4.2.0 
"@vitejs/plugin-vue": "4.1.0",
"@vitejs/plugin-vue-jsx": "3.0.0",
"vite": "2.9.13",
"vite-plugin-ruby": "3.0.12",
"vue": "3.2.47",

Used Package Manager

yarn

Logs

Output showing two different hashes after running it only twice:

https://gist.github.com/dmix/3b6aa74e667c0cc13f137f182a53b2d5

Validations

@dmix
Copy link
Author

dmix commented May 2, 2023

Looking through some older issues on Rollup, this person was able to have a reproduceable build showing different hashes:

rollup/rollup#3697

This was apparently addressed in Rollup 3 by changing how the reference IDs are set.

But I came across this issue which says that Vite uses a different scheme, at least until Vite 5. rollup/rollup#4713

Could this potentially be why the builds are non-deterministic?

@dmix
Copy link
Author

dmix commented May 2, 2023

I upgraded from 4.2.0 -> 4.3.4 and it's no longer creating different hashes. Not sure what changed in between.

@dmix
Copy link
Author

dmix commented May 2, 2023

Upon further investigation I've determined the difference between the two versions was the CDN in the import function:

    ../../public/vite/assets/application-8f133cfb.js 

    nne = function (e) {
        return "/vite/" + e;
    },
    ../../public/vite/assets/application-06ecfed2.js

    nne = function (e) {
        return "https://xyz.cloudfront.net/vite/" + e;
    },

We are using vite_ruby + vite_rails so this might be better asked in that repo. But for some reason it wasn't always using the CDN part. I'm not sure how this is inserted by Vite...

@bluwy
Copy link
Member

bluwy commented May 3, 2023

FWIW we had fixed a similar issue (#11911) in Vite 4.3.0, where the CSS build has a race condition if you have multiple CSS with the same content, causing the hash to be non-deterministic.

From what you've found so far, it doesn't seem to be the same issue. If you believe it's still a Vite issue though, please provide a repro so we can debug it.

@ttionya
Copy link

ttionya commented Jun 19, 2023

@bluwy I have encountered the same issue as well and have provided a reproducible example. https://github.com/ttionya/vite-non-deterministic-build-repro

@ttionya
Copy link

ttionya commented Jun 20, 2023

@bluwy

I have written a plugin that prints all the parameters in the transform hook. During two consecutive builds, although the order of their outputs is different, I found that there is only one instance where the content of the output differs after adjusting the order.

plugins: [
    function() {
      return {
        name: 'test',
        transform: (...args) => {
          console.log(args)
        }
      }
    }()
]

I have removed a significant amount of irrelevant code, so the hash of the artifact is different from the one in the repro.

First build:

[
  'export { __moduleExports as default } from "C:/Users/admin/Projects/My/vite-non-deterministic-build-repro/node_modules/dayjs/dayjs.min.js";',
  '\x00C:/Users/admin/Projects/My/vite-non-deterministic-build-repro/node_modules/dayjs/dayjs.min.js?commonjs-proxy'
]

[2mdist/[22m�[36massets/index-e2988d1d.js   [39m�[1m�[2m 1.10 kB�[22m�[1m�[22m�[2m  gzip:  0.63 kB�[22m
[2mdist/[22m�[36massets/vendor-3bedaa96.js  [39m�[1m�[2m81.22 kB�[22m�[1m�[22m�[2m  gzip: 32.73 kB�[22m
[32m✓ built in 1.97s�[39m

Second build:

[
  'import { getDefaultExportFromCjs } from "\x00commonjsHelpers.js";\n' +
    'import { __require as requireDayjs_min } from "C:/Users/admin/Projects/My/vite-non-deterministic-build-repro/node_modules/dayjs/dayjs.min.js";\n' +
    'var dayjs_minExports = requireDayjs_min();\n' +
    'export { dayjs_minExports as __moduleExports };export default /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);',
  '\x00C:/Users/admin/Projects/My/vite-non-deterministic-build-repro/node_modules/dayjs/dayjs.min.js?commonjs-es-import'
]

[2mdist/[22m�[36massets/index-73275ff8.js   [39m�[1m�[2m 1.10 kB�[22m�[1m�[22m�[2m  gzip:  0.63 kB�[22m
[2mdist/[22m�[36massets/vendor-2f895bab.js  [39m�[1m�[2m81.26 kB�[22m�[1m�[22m�[2m  gzip: 32.75 kB�[22m
[32m✓ built in 2.97s�[39m

Should we continue the discussion under this issue or open a new one?

@ttionya ttionya mentioned this issue Jun 29, 2023
7 tasks
@utix
Copy link

utix commented Aug 12, 2023

We have the same issue, if this can help here an example of two different output for index.js

var U0e = Object.defineProperty;                 |    var Z0e = Object.defineProperty;                
var j0e = (e, t, n) => t in e ? U0e(e, t, {      |    var Y0e = (e, t, n) => t in e ? Z0e(e, t, {     
    enumerable: !0,                              |        enumerable: !0,
    configurable: !0,                            |        configurable: !0,
    writable: !0,                                |        writable: !0,
    value: n                                     |        value: n
}) : e[t] = n;                                   |    }) : e[t] = n;
var $N = (e, t, n) => (j0e(e, typeof t != "symbo>|    var $N = (e, t, n) => (Y0e(e, typeof t != "symb>
                                                 |    
function V0e(e, t) {                             |    function X0e(e, t) {   

@tjx666
Copy link

tjx666 commented Aug 21, 2023

always build different content with core-js module:

https://www.diffchecker.com/FvnYezIw/

@tjx666
Copy link

tjx666 commented Aug 22, 2023

After investgate, I found this is cause by babel-runtime of ant design vue, our project use @babel/runtime and babel-runtime the same time. My resolution is to alias the babel-runtime to @babel/runtime like:

{
    overrides: {
        "ant-design-vue>babel-runtime": "npm:@babel/[email protected]",
    }
}

@iamriajul
Copy link

Facing the same issue! waiting for a fix.

@bluwy
Copy link
Member

bluwy commented Oct 29, 2023

Going to close this as it seems like it's a Vite Ruby issue. Otherwise for non-deterministic builds with CJS deps, it's tracked at #13672

@bluwy bluwy closed this as completed Oct 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants