angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

ng build --prod does not generate consistent hashes on different machines when run with same code base #17351

Closed naraklearn closed 4 years ago

naraklearn commented 4 years ago

Versions

angular : 8.2 & 9.1 angular-cli: 8.3 & 9.1 OS: windows 7 & 10 64bit

Repro steps

Create a site with ng new Add a lazy path with loadChildren ng build --prod Use same source code in differnt machine ng build --prod compare these two dist with same source code(no change)

Observed behavior

Same issue occurred in angular V8.2 & 9.1 versions(attached screenshot of differences in hashes for same source code). Currently production build is in angular 8.2 1) When run in different drives in same machine with same source code, Every time production build happens the hashes in the chunks does not change as no change in the source code – working as expected 2) when run in different computer machine with same source code, production build happens the hashes in the chunks changes when comparing between dist in windows 7 and dist in windows 9 though there is no changes in source code.

Desired behavior

when run in different computer machine with same source code, Every --prod build should not change the hashes in the chunks because no change made in existing code base.

what is recommended way to achieve desired behavior?

if customizing the angular-cli/webpack package is alternate approach, what is the recommended options? angular 8.2 dist comparison: image Angular 9.1 dist comparison: image

alan-agius4 commented 4 years ago

Hi @naraklearn,

Are both machines using the same Node version? Can you please share the output of ng version from both machines?

naraklearn commented 4 years ago

Angular: 8.2 Environment : Windows 10 Node : v10.17.0 ng_version_windows_10

Environment : Windows 7 Node: v10.15.3 ng_version_windows_7

Angular: 9.1 Environment: Mac Node: v10.16.3 ng_version_mac_angular9 Environment: Windows Node: v10.15.3 ng_version_windows7_angular9

What might be the root cause for this issue?

alan-agius4 commented 4 years ago

I am seeing that the node version and the packages installed are not the same version, those 2 can cause different file hashes.

  1. Use same node and package versions
  2. Use a package manager lock file and install using frozen mode (npm ci or yarn frozen-lockfile)
  3. Hashes will be different between Windows and Mac, unless you configure your line endings to be LF and not CRLF on Windows. See: https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings
naraklearn commented 4 years ago

@alan-agius4 Thanks! above mentioned solutions worked for us.

angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.