ds300 / patch-package

Fix broken node modules instantly šŸƒšŸ½ā€ā™€ļøšŸ’Ø
MIT License
10.35k stars 289 forks source link

Doesn't work with npm CI #46

Closed danieldecsi closed 6 years ago

danieldecsi commented 6 years ago

patch-package fails when using npm ci to install packages. yarn install and npm install works well. patch-package is missing from the node_modules/.bin folder, but other binaries of other dependencies are there.

npm 5.8.0 patch-package 5.1.1

0 info it worked if it ends with ok
1 verbose cli [ '/Users/danieldecsi/.nvm/versions/node/v9.4.0/bin/node',
1 verbose cli   '/Users/danieldecsi/.nvm/versions/node/v9.4.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'prepare' ]
2 info using npm@5.8.0
3 info using node@v9.4.0
4 verbose run-script [ 'prepare' ]
5 info lifecycle projectname@0.0.1~prepare: projectname@0.0.1
6 verbose lifecycle projectname@0.0.1~prepare: unsafe-perm in lifecycle true
7 verbose lifecycle projectname@0.0.1~prepare: PATH: /Users/danieldecsi/.nvm/versions/node/v9.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/danieldecsi/Projects/projectname-npm-ci/node_modules/.bin:/Users/danieldecsi/.nvm/versions/node/v9.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/danieldecsi/Projects/projectname-npm-ci/node_modules/postinstall-prepare/node_modules/.bin:/Users/danieldecsi/Projects/projectname-npm-ci/node_modules/.bin:/Users/danieldecsi/.rbenv/shims:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin:/Users/danieldecsi/.nvm/versions/node/v9.4.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/danieldecsi/Library/Android/sdk/platform-tools:/Users/danieldecsi/Library/Android/sdk/tools
8 verbose lifecycle projectname@0.0.1~prepare: CWD: /Users/danieldecsi/Projects/projectname-npm-ci
9 silly lifecycle projectname@0.0.1~prepare: Args: [ '-c', 'patch-package' ]
10 info lifecycle projectname@0.0.1~prepare: Failed to exec prepare script
11 verbose stack Error: projectname@0.0.1 prepare: `patch-package`
11 verbose stack spawn ENOENT
11 verbose stack     at ChildProcess.<anonymous> (/Users/danieldecsi/.nvm/versions/node/v9.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
11 verbose stack     at ChildProcess.emit (events.js:160:13)
11 verbose stack     at maybeClose (internal/child_process.js:943:16)
11 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
12 verbose pkgid projectname@0.0.1
13 verbose cwd /Users/danieldecsi/Projects/projectname-npm-ci
14 verbose Darwin 17.4.0
15 verbose argv "/Users/danieldecsi/.nvm/versions/node/v9.4.0/bin/node" "/Users/danieldecsi/.nvm/versions/node/v9.4.0/bin/npm" "run" "prepare"
16 verbose node v9.4.0
17 verbose npm  v5.8.0
18 error file sh
19 error code ELIFECYCLE
20 error errno ENOENT
21 error syscall spawn
22 error projectname@0.0.1 prepare: `patch-package`
22 error spawn ENOENT
23 error Failed at the projectname@0.0.1 prepare script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Related part of our package.json file:

"scripts": {
    "prepare": "patch-package"
},
"dependencies": {
    "apsl-react-native-button": "^3.1.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "color": "^2.0.0",
    "date-easter": "^0.2.2",
    "deepmerge": "^1.5.2",
    "fuse.js": "^3.2.0",
    "lodash.clonedeep": "^4.5.0",
    "lodash.debounce": "^4.0.8",
    "lodash.set": "^4.3.2",
    "lodash.throttle": "^4.1.1",
    "memoarray": "^0.1.0",
    "memobind": "^0.5.0",
    "moment": "git+https://github.com/tqc/moment#no-dynamic-import",
    "postinstall-prepare": "^1.0.1",
    "prop-types": "^15.5.10",
    "react": "16.0.0-beta.5",
    "react-extra-prop-types": "^0.3.1",
    "react-native": "0.49.3",
    "react-native-adjust": "^4.12.0",
    "react-native-android-location-services-dialog-box": "^2.3.2",
    "react-native-appboy-sdk": "^1.5.1",
    "react-native-collapsible": "^0.9.0",
    "react-native-config": "^0.9.0",
    "react-native-dash": "team-supercharge/react-native-dash#master",
    "react-native-deep-linking": "^2.1.0",
    "react-native-device-info": "0.21.2",
    "react-native-extended-stylesheet": "^0.6.0",
    "react-native-fabric": "^0.5.1",
    "react-native-fabric-crashlytics": "^0.1.8",
    "react-native-fbsdk": "team-supercharge/react-native-fbsdk#master",
    "react-native-firebase": "^3.1.1",
    "react-native-fit-image": "^1.5.2",
    "react-native-google-analytics-bridge": "5.6.2",
    "react-native-hyperlink": "^0.0.11",
    "react-native-i18n": "^2.0.5",
    "react-native-image-sequence": "^0.5.0",
    "react-native-iphone-x-helper": "^1.0.1",
    "react-native-keyboard-aware-scroll-view": "^0.4.1",
    "react-native-open-settings": "^1.0.1",
    "react-native-permissions": "yonahforst/react-native-permissions#master",
    "react-native-phone-call": "^1.0.4",
    "react-native-read-more-text": "^1.0.0",
    "react-native-redux-toast": "team-supercharge/react-native-redux-toast#master",
    "react-native-root-modal": "^3.0.0",
    "react-native-section-list-get-item-layout": "^2.0.0",
    "react-native-slider": "^0.11.0",
    "react-navigation": "1.0.0-beta.19",
    "react-redux": "^5.0.6",
    "recompose": "^0.26.0",
    "redux": "^3.7.2",
    "redux-actions": "^2.2.1",
    "redux-batched-actions": "^0.1.6",
    "redux-form": "^7.1.1",
    "redux-logger": "^3.0.6",
    "redux-observable": "^0.17.0",
    "redux-persist": "^5.4.0",
    "redux-thunk": "^2.2.0",
    "remove-accents": "^0.4.2",
    "reselect": "^3.0.1",
    "rxjs": "5.5.2"
},
"devDependencies": {
    "babel-eslint": "^7.2.3",
    "babel-jest": "20.0.3",
    "babel-plugin-module-resolver": "^2.7.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-react-native": "3.0.1",
    "dotize": "^0.2.0",
    "eslint": "^4.5.0",
    "eslint-config-airbnb": "^15.1.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-prefer-object-spread": "^1.2.1",
    "eslint-plugin-react": "^7.3.0",
    "eslint-plugin-react-native": "^3.0.1",
    "gulp": "3.9.0",
    "gulp-file": "^0.3.0",
    "jest": "20.0.4",
    "patch-package": "^5.1.1",
    "react-addons-perf": "^15.4.2",
    "react-native-debugger-open": "^0.3.15",
    "react-native-schemes-manager": "Thinkmill/react-native-schemes-manager#master",
    "react-test-renderer": "16.0.0-alpha.12",
    "why-did-you-update": "^0.1.0"
},
ds300 commented 6 years ago

It seems npm ci doesn't run the prepare hook. You can use the postinstall hook too, which works with npm ci. Maybe I should update the readme to reflect that.

danieldecsi commented 6 years ago

postinstall works, thank you.

DanielRuf commented 6 years ago

It seems npm ci doesn't run the prepare hook. You can use the postinstall hook too, which works with npm ci. Maybe I should update the readme to reflect that.

This will be just updated when there is a new release on npmjs.

ab-pm commented 1 month ago

patch-package is missing from the node_modules/.bin folder

Isn't the problem rather that patch-package is a devDependency and not a dependency in your package.json?

Personally I've used only a prepare script that doesn't run when building in the CI, and rather use manual patch application with git apply --no-index patches/*.patch instead of installing patch-package in production.

DanielRuf commented 1 month ago

This is a rather old issue and was resolved. So far it doesn't matter here, if dependencies or devDependencies is used.