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

Patches not being applied during Jenkins builds #97

Closed
martinmckenna opened this issue Nov 29, 2018 · 15 comments
Closed

Patches not being applied during Jenkins builds #97

martinmckenna opened this issue Nov 29, 2018 · 15 comments

Comments

@martinmckenna
Copy link

I have installed patch-package to use in my react-app and running locally, everything works fine. With an update to date patch file, running yarn && yarn run build correctly applies the patches.

However, when Jenkins tries to run yarn && yarn run build, the patches do not get applied correctly. I have tried installing both patch-packaage and postinstall-postinstall as both a regular dependency and a dev dependency.

Is there any other obvious steps I might be missing here? Has anyone tried using this package with a deployment process, such as Circle CI or Jenkins?

@sergonius
Copy link

Also fails in Netlify.

@ds300
Copy link
Owner

ds300 commented Jan 12, 2019

Thanks for the report! 🙏

I haven't been able to reproduce this issue on netlify (I tested various versions of patch-package and they all worked). and I don't have a jenkins setup to test on.

If you could provide the error messages it might help me to fix these issues.

@sergonius
Copy link

Forgot to update here, but I used the description here to set it up:
https://www.npmjs.com/package/patch-package
And prepare failed for me whereas postinstall worked.

Perhaps the npmjs page should be updated?

@martinmckenna
Copy link
Author

martinmckenna commented Jan 16, 2019

Below is the output from the Jenkins build. As you can see the patch-package never ran. Yet running yarn run build locally has the patches applied no problemo

The issue I was trying to solve was that create-react-app 2 does not allow for absolute imports, so I wanted to alter the react-scripts package, so that I could do something like import blah from 'src/someDir/someFile

Step 20/25 : RUN yarn run build

 ---> Running in afd93fe28352

yarn run v1.12.3

$ NODE_PATH=./ react-scripts build

The following changes are being made to your tsconfig.json file:

  - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))

  - compilerOptions.paths must not be set (aliased imports are not supported)



Creating an optimized production build...

Failed to compile.



/app/packages/apps/src/features/InstanceDetail/InstanceDetail.tsx

Type error: Cannot find module 'src/components/Typography'.  TS2307



     5 | import Grid from '../../components/Grid';

     6 | 

  >  7 | import { FormattedMessage } from 'src/components/Typography';

       |                                  ^

     8 | import LandingError from '../../components/LandingError';

     9 | import LandingLoading from '../../components/LandingLoading';

    10 |

And here's my package.json

{
  "name": "apps",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^3.3.0",
    "@material-ui/icons": "^3.0.1",
    "@sentry/browser": "^4.2.1",
    "classnames": "^2.2.6",
    "create-react-app": "^2.1.0",
    "lodash": "^4.17.11",
    "md5": "^2.2.1",
    "moize": "^5.4.1",
    "notistack": "^0.3.7",
    "pure-react-carousel": "^1.16.2",
    "react-ga": "^2.5.3",
    "react-intl": "^2.7.2",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^2.1.1",
    "recompose": "^0.30.0",
    "store": "^2.0.12",
    "svg-react-loader": "^0.4.6",
    "uuid": "^3.3.2"
  },
  "scripts": {
    "ci:test": "NODE_PATH=./ CI=true react-scripts test",
    "start": "BROWSER=none NODE_PATH=./ react-scripts start",
    "build": "NODE_PATH=./ react-scripts build",
    "test": "NODE_PATH=./ react-scripts test",
    "eject": "NODE_PATH=./ react-scripts eject",
    "lint": "NODE_PATH=./ tslint src/**/*.{ts,tsx}",
    "format": "NODE_PATH=./ prettier src/**/*.{ts,tsx} --write",
    "type": "NODE_PATH=./ tsc --noEmit",
    "manage:translations": "node ./scripts/extractForTranslation.js",
    "postinstall": "patch-package"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@babel/core": "^7.1.2",
    "@types/classnames": "^2.2.6",
    "@types/enzyme": "^3.1.14",
    "@types/enzyme-adapter-react-16": "^1.0.3",
    "@types/lodash": "^4.14.117",
    "@types/md5": "^2.1.33",
    "@types/react-intl": "^2.3.11",
    "@types/react-router-dom": "^4.3.1",
    "@types/recompose": "^0.27.0",
    "@types/store": "^2.0.0",
    "@types/uuid": "^3.4.4",
    "babel-loader": "^8.0.4",
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.6.0",
    "husky": "^1.1.2",
    "lint-staged": "^7.3.0",
    "patch-package": "^5.1.1",
    "postinstall-postinstall": "^2.0.0",
    "prettier": "^1.14.3",
    "react-intl-translations-manager": "^5.0.3",
    "react-test-renderer": "^16.6.0",
    "rimraf": "^2.6.2",
    "tslint": "^5.11.0",
    "tslint-config-prettier": "^1.15.0",
    "tslint-react": "^3.6.0",
    "typescript-react-intl": "^0.3.0"
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "yarn format",
      "yarn lint --fix",
      "git add"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "yarn ci:test && yarn type && lint-staged"
    }
  }
}

@ds300
Copy link
Owner

ds300 commented Jan 16, 2019

@martinmckenna Thanks for the details! So running yarn on jenkins completes successfully but the postinstall hook is not executed?

@sergonius Yeah I'm going to update that. Thanks for pointing it out!

@martinmckenna
Copy link
Author

@ds300 Exactly. The

The following changes are being made to your tsconfig.json file:

  - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))

  - compilerOptions.paths must not be set (aliased imports are not supported)

Is the exact thing I was patching

@0xpatrickdev
Copy link

0xpatrickdev commented Jan 17, 2019

Has anyone figured out how to get this working with Zeit now? I've tried both postinstall-postinstall and postinstall-prepare but neither seems to be working. The build just hangs :/

There are a few discussions here:
vercel/vercel#1666
vercel/vercel#1661
https://github.com/zeit/now-builders/issues/49

Edit: I am also using yarn.

@ds300
Copy link
Owner

ds300 commented Jan 17, 2019 via email

@0xpatrickdev
Copy link

Awesome, thank you for the quick respo

@0xpatrickdev
Copy link

Still no dice unfortunately, getting the same error which looks like this:

image

@ds300
Copy link
Owner

ds300 commented Jan 17, 2019 via email

@ds300
Copy link
Owner

ds300 commented Jan 27, 2019

v6.0.0 was just released! So I'm going to close this. As mentioned patch-package now doesn't use git when applying patches so it should work wherever node works.

@ds300 ds300 closed this as completed Jan 27, 2019
@martinmckenna
Copy link
Author

So as an update - I figured out my issue wasn't with Jenkins, but instead I wasn't copying over the /patches dir into my Docker container.

So when I ran yarn, it has no idea of the existence of the patch

@justingrant
Copy link

BTW, if anyone runs across this same problem deploying to Netlify, one thing to check is whether you're actually running the same dependency files locally vs. Netlify (or CI or...).

In my case, I was patching React and was running the development version locally and the minified version of react in Netlify. But my original patch only patched React's development bundle file. Once I patched the prod bundle too, everything worked great.

@Venryx
Copy link

Venryx commented Aug 25, 2021

To help debug what is going wrong with patch-package, when using Yarn v2, add the --inline-builds flag: yarn install --inline-builds

This causes yarn to output the log messages from all the build scripts, letting you see any errors that patch-package may be hitting. (in my case, the problem was that I had a symlinked package which caused a [sub]dependency of both my app and lib to resolve to a different version than on my host computer, causing patch-package to be unable to match the patch-file to the files in the within-docker node_modules folder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants