vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.17k stars 287 forks source link

Compilation differs on GitHub Actions vs locally #831

Open sethvargo opened 2 years ago

sethvargo commented 2 years ago

When using the same version of ncc locally (OS X) and on GitHub Actions, the compiled file is slightly different (full diff):

diff --git a/dist/index.js b/dist/index.js
index 720bbbd..217b40a 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -55565,7 +55565,7 @@ module.exports = __nccwpck_require__(4083).YAML
 /***/ ((module) => {

 "use strict";
-module.exports = JSON.parse('{"license":"Apache-2.0"}');
+module.exports = JSON.parse('{"license":"Apache-2.0","_resolved":"https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.10.4.tgz","_integrity":"sha512-DJ4VGaLwgPcMg8hMZFoQxjA0VeIy2A1RkJ6kUt5vXNfbVEma8WA9waUJ29cwpXjpFjpEAT2Uu6Y5loYbmInyFw==","_from":"google-auth-library@7.10.4"}');

This causes a perpetual diff between what's built locally and what's built by CI.

styfle commented 2 years ago

Are you using typescript? This sounds like it could be the same issue as #820

sethvargo commented 2 years ago

We are using Typescript, but I don't think it's the same as #820, as there is a version property in the package.json.

Also, the build is succeeding, it just has different output when run on GitHub Actions vs when run locally.

KhudaDad414 commented 2 years ago

same here. I am not using Typescript. Local Machine: Windows GitHub Actions: Ubuntu GitHub Actions output:

Detected uncommitted changes after build.  See status below:
diff --git a/dist/index.js b/dist/index.js
index 24d024e..ce6d5ac 100644
Binary files a/dist/index.js and b/dist/index.js differ
Error: Process completed with exit code 1.
styfle commented 2 years ago

Are you using the same version of npm locally and in CI?

What about the same OS?

sethvargo commented 2 years ago

Yes and same node version too. Deps are installed via "npm ci" and the lines in the compiled code are NOT in the package.json.

I've confirmed this my echoing the contents of package.json before "npm ci", after, and after "ncc". The contents never change and never include the "_resolved" references in the compiled js.

rethab commented 2 years ago

@sethvargo might it be this problem? https://github.com/vercel/ncc/issues/713

sethvargo commented 2 years ago

I don't think so, because the difference only occurs with ncc - npm ci and npm install do not generate a different lock.

rethab commented 2 years ago

Fair enough. Do you have a reproducing sample for this? Looks like the branch you linked in the issue description is gone? (I can see the workflow logs, but not the branch it was run from)

sethvargo commented 2 years ago

@rethab sure - I spent some time to remove all irrelevant code in my fork: https://github.com/sethvargo/get-gke-credentials/runs/4888123729. The repo is on main.

rethab commented 2 years ago

Hi @sethvargo , I have only very briefly checked your reproducer, but npm ci did make a difference when I tried so I would encourage you to revisit the issue I linked earlier.

I have forked your reproducer here: https://github.com/rethab/get-gke-credentials All I did to make it green was to run npm ci before npm run package and then commit the updated dist folder.


npm ci and npm install do not generate a different lock.

They don't generate a different package-lock.json in your project (in fact npm ci doesn't touch this file). However, what they do is they install packages differently. This results in different contents/structure in the node_modules folder. My analysis in https://github.com/vercel/ncc/issues/713 has more details on this.

Perhaps I'm wrong and you are indeed facing a different issue, but if you are facing the same issue, then here are two options I am aware of:

sethvargo commented 2 years ago

Hi @rethab

Thank you for looking into this. Running npm ci on my Mac produces no git diff. If I clone a fresh https://github.com/sethvargo/get-gke-credentials and run npm ci, there are no changes. Deleting the entire node_modules directory and running npm ci also doesn't generate a diff.

There is no npm run package step, so I'm not sure what you're referring to here. If you meant npm run build, deleting node_modules, running npm ci, and running npm run build also generates no diff. Per https://github.com/rethab/get-gke-credentials/commit/73ece2dcfd70696d7aa7bdb136f23f87236362a6, there has to be some diff that's generated.

Regarding using Node 16, https://github.com/actions/runner/pull/1439 was merged, and released in https://github.com/actions/runner/releases/tag/v2.285.0, but it will also likely be a few months until it's available in GitHub Enterprise installations. A lot of our users use self-hosted runners with GitHub Enterprise, so we can't switch until it's made available everywhere.

rethab commented 2 years ago

Okay, got it. I'm not at a computer anymore, so I can't very what I'm going to say, but I believe GH is using npm 6 with node 12. From what I remember, there was a difference between npm versions and how node_modules are laid out.

Could you please try using npm 6 on your mac? (npx ***@***.*** ci would be the command I think).

-------- Oorspronkelijk bericht -------- Aan 21 jan. 2022 15:33, Seth Vargo schreef:

Hi @.***(https://github.com/rethab)

Thank you for looking into this. Running npm ci on my Mac produces no git diff. If I clone a fresh https://github.com/sethvargo/get-gke-credentials and run npm ci, there are no changes. Deleting the entire node_modules directory and running npm ci also doesn't generate a diff.

There is no npm run package step, so I'm not sure what you're referring to here. If you meant npm run build, deleting node_modules, running npm ci, and running npm run build also generates no diff. Per @.***(https://github.com/rethab/get-gke-credentials/commit/73ece2dcfd70696d7aa7bdb136f23f87236362a6), there has to be some diff that's generated.

  • Mac OS 12.1 (21C52)
  • Node v12.22.5
  • NPM 8.3.0

Regarding using Node 16, actions/runner#1439 was merged, and released in https://github.com/actions/runner/releases/tag/v2.285.0, but it will also likely be a few months until it's available in GitHub Enterprise installations. A lot of our users use self-hosted runners with GitHub Enterprise, so we can't switch until it's made available everywhere.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

sethvargo commented 2 years ago

Hi @rethab thanks for the reply. I think GitHub or your email client did something odd. The command came in as npx ***@***.*** ci

CleanShot 2022-01-21 at 09 47 41@2x

Don't worry about replying until you're back at a computer - this isn't a P0 since we have a workaround for now.

rethab commented 2 years ago

GitHub thinks it's an email address and masks it 😅

All I wanted to say was try npm six. The command I showed was to use npx and specify the version of npm after the @.

npx npm[at]6 ci

-------- Oorspronkelijk bericht -------- Aan 21 jan. 2022 15:48, Seth Vargo schreef:

Hi @.(https://github.com/rethab) thanks for the reply. I think GitHub or your email client did something odd. The command came in as npx @. ci

[CleanShot 2022-01-21 at 09 47 @.***(https://user-images.githubusercontent.com/408570/150547039-f172dcbe-48ae-4f0c-a884-56728baa7dd7.png)

Don't worry about replying until you're back at a computer - this isn't a P0 since we have a workaround for now.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

sethvargo commented 2 years ago

Welp, that seems to be the issue:

$ rm -rf node_modules && npx npm@6 ci && npx npm@6 run build
added 46 packages in 1.028s

> get-gke-credentials@0.5.0 build /Users/sethvargo/get-gke-credentials
> ncc build src/main.ts

ncc: Version 0.33.1
ncc: Compiling file index.js into CJS
ncc: Using typescript@4.5.5 (local user-provided)
1617kB  dist/index.js
1617kB  [3422ms] - ncc 0.33.1
➜  get-gke-credentials main ❃ git diff
diff --git a/dist/index.js b/dist/index.js
index 9e0f160..9535565 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -45624,7 +45624,7 @@ module.exports = require("zlib");
 /***/ ((module) => {

 "use strict";
-module.exports = JSON.parse('{"name":"google-auth-library","version":"7.11.0","author":"Google Inc.","description":"Google APIs Authentication Client Library for Node.js","engines":{"node":">=10"},"main":"./build/src/index.js","types":"./build/src/index.d.ts","repository":"googleapis/google-auth-library-nodejs.git","keywords":["google","api","google apis","client","client library"],"dependencies":{"arrify":"^2.0.0","base64-js":"^1.3.0","ecdsa-sig-formatter":"^1.0.11","fast-text-encoding":"^1.0.0","gaxios":"^4.0.0","gcp-metadata":"^4.2.0","gtoken":"^5.0.4","jws":"^4.0.0","lru-cache":"^6.0.0"},"devDependencies":{"@compodoc/compodoc":"^1.1.7","@types/base64-js":"^1.2.5","@types/chai":"^4.1.7","@types/jws":"^3.1.0","@types/lru-cache":"^5.0.0","@types/mocha":"^8.0.0","@types/mv":"^2.1.0","@types/ncp":"^2.0.1","@types/node":"^16.0.0","@types/sinon":"^10.0.0","@types/tmp":"^0.2.0","assert-rejects":"^1.0.0","c8":"^7.0.0","chai":"^4.2.0","codecov":"^3.0.2","execa":"^5.0.0","gts":"^2.0.0","is-docker":"^2.0.0","karma":"^6.0.0","karma-chrome-launcher":"^3.0.0","karma-coverage":"^2.0.0","karma-firefox-launcher":"^2.0.0","karma-mocha":"^2.0.0","karma-remap-coverage":"^0.1.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^5.0.0","keypair":"^1.0.4","linkinator":"^2.0.0","mocha":"^8.0.0","mv":"^2.1.1","ncp":"^2.0.0","nock":"^13.0.0","null-loader":"^4.0.0","puppeteer":"^13.0.0","sinon":"^12.0.0","tmp":"^0.2.0","ts-loader":"^8.0.0","typescript":"^3.8.3","webpack":"^5.21.2","webpack-cli":"^4.0.0"},"files":["build/src","!build/src/**/*.map"],"scripts":{"test":"c8 mocha build/test","clean":"gts clean","prepare":"npm run compile","lint":"gts check","compile":"tsc -p .","fix":"gts fix","pretest":"npm run compile","docs":"compodoc src/","samples-setup":"cd samples/ && npm link ../ && npm run setup && cd ../","samples-test":"cd samples/ && npm link ../ && npm test && cd ../","system-test":"mocha build/system-test --timeout 60000","presystem-test":"npm run compile","webpack":"webpack","browser-test":"karma start","docs-test":"linkinator docs","predocs-test":"npm run docs","prelint":"cd samples; npm link ../; npm install","precompile":"gts clean"},"license":"Apache-2.0"}');
+module.exports = JSON.parse('{"name":"google-auth-library","version":"7.11.0","author":"Google Inc.","description":"Google APIs Authentication Client Library for Node.js","engines":{"node":">=10"},"main":"./build/src/index.js","types":"./build/src/index.d.ts","repository":"googleapis/google-auth-library-nodejs.git","keywords":["google","api","google apis","client","client library"],"dependencies":{"arrify":"^2.0.0","base64-js":"^1.3.0","ecdsa-sig-formatter":"^1.0.11","fast-text-encoding":"^1.0.0","gaxios":"^4.0.0","gcp-metadata":"^4.2.0","gtoken":"^5.0.4","jws":"^4.0.0","lru-cache":"^6.0.0"},"devDependencies":{"@compodoc/compodoc":"^1.1.7","@types/base64-js":"^1.2.5","@types/chai":"^4.1.7","@types/jws":"^3.1.0","@types/lru-cache":"^5.0.0","@types/mocha":"^8.0.0","@types/mv":"^2.1.0","@types/ncp":"^2.0.1","@types/node":"^16.0.0","@types/sinon":"^10.0.0","@types/tmp":"^0.2.0","assert-rejects":"^1.0.0","c8":"^7.0.0","chai":"^4.2.0","codecov":"^3.0.2","execa":"^5.0.0","gts":"^2.0.0","is-docker":"^2.0.0","karma":"^6.0.0","karma-chrome-launcher":"^3.0.0","karma-coverage":"^2.0.0","karma-firefox-launcher":"^2.0.0","karma-mocha":"^2.0.0","karma-remap-coverage":"^0.1.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^5.0.0","keypair":"^1.0.4","linkinator":"^2.0.0","mocha":"^8.0.0","mv":"^2.1.1","ncp":"^2.0.0","nock":"^13.0.0","null-loader":"^4.0.0","puppeteer":"^13.0.0","sinon":"^12.0.0","tmp":"^0.2.0","ts-loader":"^8.0.0","typescript":"^3.8.3","webpack":"^5.21.2","webpack-cli":"^4.0.0"},"files":["build/src","!build/src/**/*.map"],"scripts":{"test":"c8 mocha build/test","clean":"gts clean","prepare":"npm run compile","lint":"gts check","compile":"tsc -p .","fix":"gts fix","pretest":"npm run compile","docs":"compodoc src/","samples-setup":"cd samples/ && npm link ../ && npm run setup && cd ../","samples-test":"cd samples/ && npm link ../ && npm test && cd ../","system-test":"mocha build/system-test --timeout 60000","presystem-test":"npm run compile","webpack":"webpack","browser-test":"karma start","docs-test":"linkinator docs","predocs-test":"npm run docs","prelint":"cd samples; npm link ../; npm install","precompile":"gts clean"},"license":"Apache-2.0","_resolved":"https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.11.0.tgz","_integrity":"sha512-3S5jn2quRumvh9F/Ubf7GFrIq71HZ5a6vqosgdIu105kkk0WtSqc2jGCRqtWWOLRS8SX3AHACMOEDxhyWAQIcg==","_from":"google-auth-library@7.11.0"}');

 /***/ }),

So is the best option here to wait until node16 is more broadly available on Actions?

rethab commented 2 years ago

I'm not sure. I'm not involved with ncc or npm, I'm just a user who discovered this issue.

I can only tell you what we do: developers must use npm 6 and we have the above-mentioned "all" script (when I said package, I meant build). While this might not sound like a nice workaround, we haven't had issues since (and we have around 20 actions under active development).

To be frank, I don't remember if node 16 comes with npm 8, but from what I recall that is going to resolve the issue and I'm eager to upgrade. Just didn't get to it yet :)

-------- Oorspronkelijk bericht -------- Aan 21 jan. 2022 16:10, Seth Vargo schreef:

Welp, that seems to be the issue:

$ rm -rf node_modules && npx @. ci && npx @. run build added 46 packages in 1.028s

@.*** build /Users/sethvargo/get-gke-credentials ncc build src/main.ts

ncc: Version 0.33.1 ncc: Compiling file index.js into CJS ncc: Using @. (local user-provided) 1617kB dist/index.js 1617kB [3422ms] - ncc 0.33.1 ➜ get-gke-credentials main ❃ git diff diff --git a/dist/index.js b/dist/index.js index 9e0f160..9535565 100644 --- a/dist/index.js +++ b/dist/index.js @@ -45624,7 +45624,7 @@ module.exports = require("zlib"); // ((module) => {

"use strict"; -module.exports = JSON.parse('{"name":"google-auth-library","version":"7.11.0","author":"Google Inc.","description":"Google APIs Authentication Client Library for Node.js","engines":{"node":">=10"},"main":"./build/src/index.js","types":"./build/src/index.d.ts","repository":"googleapis/google-auth-library-nodejs.git","keywords":["google","api","google apis","client","client @.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.*/tmp":"^0.2.0","assert-rejects":"^1.0.0","c8":"^7.0.0","chai":"^4.2.0","codecov":"^3.0.2","execa":"^5.0.0","gts":"^2.0.0","is-docker":"^2.0.0","karma":"^6.0.0","karma-chrome-launcher":"^3.0.0","karma-coverage":"^2.0.0","karma-firefox-launcher":"^2.0.0","karma-mocha":"^2.0.0","karma-remap-coverage":"^0.1.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^5.0.0","keypair":"^1.0.4","linkinator":"^2.0.0","mocha":"^8.0.0","mv":"^2.1.1","ncp":"^2.0.0","nock":"^13.0.0","null-loader":"^4.0.0","puppeteer":"^13.0.0","sinon":"^12.0.0","tmp":"^0.2.0","ts-loader":"^8.0.0","typescript":"^3.8.3","webpack":"^5.21.2","webpack-cli":"^4.0.0"},"files":["build/src","!build/src//.map"],"scripts":{"test":"c8 mocha build/test","clean":"gts clean","prepare":"npm run compile","lint":"gts check","compile":"tsc -p .","fix":"gts fix","pretest":"npm run compile","docs":"compodoc src/","samples-setup":"cd samples/ && npm link ../ && npm run setup && cd ../","samples-test":"cd samples/ && npm link ../ && npm test && cd ../","system-test":"mocha build/system-test --timeout 60000","presystem-test":"npm run compile","webpack":"webpack","browser-test":"karma start","docs-test":"linkinator docs","predocs-test":"npm run docs","prelint":"cd samples; npm link ../; npm install","precompile":"gts clean"},"license":"Apache-2.0"}'); +module.exports = JSON.parse('{"name":"google-auth-library","version":"7.11.0","author":"Google Inc.","description":"Google APIs Authentication Client Library for Node.js","engines":{"node":">=10"},"main":"./build/src/index.js","types":"./build/src/index.d.ts","repository":"googleapis/google-auth-library-nodejs.git","keywords":["google","api","google apis","client","client @*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.**@*.*/tmp":"^0.2.0","assert-rejects":"^1.0.0","c8":"^7.0.0","chai":"^4.2.0","codecov":"^3.0.2","execa":"^5.0.0","gts":"^2.0.0","is-docker":"^2.0.0","karma":"^6.0.0","karma-chrome-launcher":"^3.0.0","karma-coverage":"^2.0.0","karma-firefox-launcher":"^2.0.0","karma-mocha":"^2.0.0","karma-remap-coverage":"^0.1.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^5.0.0","keypair":"^1.0.4","linkinator":"^2.0.0","mocha":"^8.0.0","mv":"^2.1.1","ncp":"^2.0.0","nock":"^13.0.0","null-loader":"^4.0.0","puppeteer":"^13.0.0","sinon":"^12.0.0","tmp":"^0.2.0","ts-loader":"^8.0.0","typescript":"^3.8.3","webpack":"^5.21.2","webpack-cli":"^4.0.0"},"files":["build/src","!build/src//.map"],"scripts":{"test":"c8 mocha build/test","clean":"gts clean","prepare":"npm run compile","lint":"gts check","compile":"tsc -p .","fix":"gts fix","pretest":"npm run compile","docs":"compodoc src/","samples-setup":"cd samples/ && npm link ../ && npm run setup && cd ../","samples-test":"cd samples/ && npm link ../ && npm test && cd ../","system-test":"mocha build/system-test --timeout 60000","presystem-test":"npm run compile","webpack":"webpack","browser-test":"karma start","docs-test":"linkinator docs","predocs-test":"npm run docs","prelint":"cd samples; npm link ../; npm install","precompile":"gts @*.***"}');

/***/ }),

So is the best option here to wait until node16 is more broadly available on Actions?

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

rickstaa commented 2 years ago

I followed the steps provided by @rethab, but I am still experiencing #831 with node: v16.16.0, npm: v8.11.0 and ncc: Version 0.31.1(see https://github.com/rickstaa/top-issues-action/runs/7520924672?check_suite_focus=true). I also ensured I installed the same versions on my local PC as in the GitHub action (see https://github.com/rickstaa/top-issues-action/blob/main/.github/workflows/check-dist.yml), but the dist folder in the GitHub action is still different from my local version. Does anybody maybe have an idea why the difference check is failing? I got one successful run but can not find out what is different (see https://github.com/rickstaa/top-issues-action/runs/7519296142?check_suite_focus=true).

What I already tried

  1. Removing the node_modules and package-lock.json files.
  2. Installing the dependencies on my local PC using both the npm ci and npm i commands.
  3. Running both the npm build and npm package commands.
rethab commented 2 years ago

Can you please change the git diff to git diff --text such that I can see what the difference actually is?

rickstaa commented 2 years ago

@rethab Thanks for your fast answer. I now added a line showing the git diff --text (see https://github.com/rickstaa/top-issues-action/actions/runs/2740998372). I also included the dist folders from the repo and the action below:

dist_repo.zip dist.zip

The only difference is between the index.js.map files.

rethab commented 2 years ago

The only difference is between the index.js.map files.

In your logs, I also see dist/index.js differ.

But if the map files are indeed the only ones that differ, why are you generating them in the first place? Please note that I never generate them and this issue is only about dist/index.js :)

rickstaa commented 2 years ago

In your logs, I also see dist/index.js differ.

Yea, in the diff in the action, the dist/index.js is also said to differ. I think git diff is confused since it says an exact replica of the file replaced the whole file. I compared the files locally; they are exactly the same, even the return characters. I tried removing the dist folder and package-json.json to fix this, but the action keeps reporting differences that are not there (see https://github.com/rickstaa/top-issues-action/runs/7535091617?check_suite_focus=true). Kind of a mystery. Maybe there are some other hidden characters that I'm unaware of.

But if the map files are indeed the only ones that differ, why are you generating them in the first place? Please note that I never generate them and this issue is only about dist/index.js :)

They are generated because the template I used specified that. I now removed them as I do agree with you that, in this case, they should not be shipped in production.

Local files

dist_local.zip

Action files

dist_action.zip

rickstaa commented 2 years ago

After all, it seemed to be a line-ending problem, which was introduced by me working on both a Linux and Windows PC. After again changing the line endings and enabling git config core.autocrlf on windows, the problem seems to be fixed.

Justin-JHG commented 1 year ago

@rickstaa wondering how your one works, I dev on Windows and run action in Ubuntu and it always failing with the git diff for index.js.map file. I did manual compare, the local windows one has extra \r\ in it compare to the one in Ubuntu, and the following doesn't seem to ignore it : if [ "$(git diff --ignore-cr-at-eol --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then

Justin-JHG commented 1 year ago

I got the exact issue while dev on windows and run action on Linux

I fixed by udpating package.json as following:

so I added newLine option for tsc build `

"scripts": {

"build": "tsc --newLine lf",
"format": "prettier --write src/**/*.ts",
"format-check": "prettier --check src/**/*.ts",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --no-cache --license licenses.txt",
"test": "jest --passWithNoTests",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"

},

cryi commented 1 year ago

I had to add --external encoding to the ncc build. I wasn't able to figure out yet why it bundles in encoding on my desktop and not within github action. Node, npm, ncc everything uses same version 🤷🏻 But at least it works when I exclude encoding manually.

IvanZosimov commented 1 year ago

Hi, all 👋 , in https://github.com/actions/setup-java repo we faced pretty the same issue. The result output of the build command is different on Windows and macOS/Linux. Here you can check the output .js files: Windows: windows.zip Linux: linux.zip Output of the git diff command can be found here: gitDiff.zip

Runners specification: Tool Ubuntu 22.04.1 Windows 11
TS 4.2.3 4.2.3
Node.js 16.19.0 16.19.1
NPM 8.19.3 8.19.3
NCC 0.33.4 0.33.4

If you open the git diff output you may notice that the innards of these files are identical (same number of lines, same blocks of code), only structure is different - some blocks of code are shifted.

We don't have such a problem in other repos where we use ncc, like https://github.com/actions/setup-node files built on different OS are identical. Could you give us a hint, what we are doing wrong? Can we even expect that the built files should be identical ?

Rubilmax commented 1 year ago

I had to add --external encoding to the ncc build. I wasn't able to figure out yet why it bundles in encoding on my desktop and not within github action. Node, npm, ncc everything uses same version 🤷🏻 But at least it works when I exclude encoding manually.

Thanks, but it didn't solve the issue for me: https://github.com/Rubilmax/foundry-gas-diff/actions/runs/5253244964/jobs/9490315554 (commit https://github.com/Rubilmax/foundry-gas-diff/commit/69fea8eb7a14a248c05c7eadbf6ee31174a745a0)

Rubilmax commented 1 year ago

It has to do something with GitHub actions runner OS because I haven't changed the version of ncc I use, and still my build went different

SayakMukhopadhyay commented 1 year ago

I think I have got the problem. Running tsc on Windows will generate the lib folder with everything in CRLF. Now, if ncc build --source-map is run, it will bundle the files in the lib folder, with the CRLF endings. To fix on my end, I manually updated the line endings of the files in lib and then executed ncc build ... and now GitHub actions doesn't show the problem.

Of course as per https://github.com/actions/typescript-action/issues/528#issuecomment-1272512783, the diff command must use --text to ensure that the diff recognises the files as text and not binary.

Kurt-von-Laven commented 1 year ago

We ran into the same issue in ScribeMD/docker-cache and were able to address it with yarn run ncc cache clean. Before clearing the cache, the behavior of yarn run ncc build src/main.ts --out dist/main --minify was not consistent even on my development laptop. Disabling minification was another, less desirable, workaround we found. I am curious whether clearing the ncc cache works for anyone else facing nondeterministic results.

IvanZosimov commented 1 year ago

Hi, @Kurt-von-Laven, unfortunately, for us your solution didn't work out. For reference, https://github.com/vercel/ncc/issues/831#issuecomment-1481275242

SayakMukhopadhyay commented 1 year ago

@IvanZosimov could you try my method as mentioned in https://github.com/vercel/ncc/issues/831#issuecomment-1594540905

Kurt-von-Laven commented 1 year ago

@SayakMukhopadhyay, it sounds like there are separate bugs since we aren't using Windows at all.

kevva commented 1 year ago

If you have a .gitattributes file in your project you can put * text=auto eol=lf at the top to always use LF line endings and it'll respect that.

Kurt-von-Laven commented 1 year ago

There are definitely at least two different bugs here then, because we already had equivalent settings in our .gitattributes when we encountered this issue.

chriscarrollsmith commented 1 year ago

I had to add --external encoding to the ncc build. I wasn't able to figure out yet why it bundles in encoding on my desktop and not within github action. Node, npm, ncc everything uses same version 🤷🏻 But at least it works when I exclude encoding manually.

Thank you so much. This resolved my issue.