question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to create patch file for complex package version

See original GitHub issue

Thanks for your work on this! I really hope we can start using it in our project. We are currently using a canary build of a package, gatsby-source-contentful and installing it using a non-standard version. However, when I try to create a patch, there is a failure finding associated data in the lock file.

$ yarn patch-package gatsby-source-contentful
yarn run v1.22.5
$ /Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/.bin/patch-package gatsby-source-contentful
patch-package 6.2.2
• Creating temporary folder
Error: Can't find lockfile entry for gatsby-source-contentful
    at Object.getPackageResolution (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/getPackageResolution.js:41:19)
    at Object.makePatch (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/makePatch.js:49:66)
    at /Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/index.js:48:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/index.js:47:22)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Module.require (internal/modules/cjs/loader.js:965:19)
/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/makePatch.js:183
        throw e;
        ^

Error: Can't find lockfile entry for gatsby-source-contentful
    at Object.getPackageResolution (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/getPackageResolution.js:41:19)
    at Object.makePatch (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/makePatch.js:49:66)
    at /Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/index.js:48:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/patch-package/dist/index.js:47:22)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Module.require (internal/modules/cjs/loader.js:965:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It also fails if I try to supply the explicit version as it is shown in the lock file:

$ yarn patch-package 'gatsby-source-contentful@^2.3.55-next.21'
yarn run v1.22.5
$ /Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/.bin/patch-package gatsby-source-contentful@^2.3.55-next.21
patch-package 6.2.2
No such package gatsby-source-contentful@^2.3.55-next.21

  File not found: /Users/davidhouse/Code/sandbox/frontend/butcherbox-frontend/node_modules/gatsby-source-contentful@^2.3.55-next.21/package.json
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

package.json

"gatsby-source-contentful": "^2.3.55-next.21",

yarn.lock

gatsby-source-contentful@^2.3.55-next.21:
  version "2.3.55-next.21"
  resolved "https://registry.yarnpkg.com/gatsby-source-contentful/-/gatsby-source-contentful-2.3.55-next.21.tgz#0e8f15f87061c094efcbd1f02dc6a87389c72b54"
  integrity sha512-tXWbaA7ByB5QbQs6if4LsnlN11H0F5VZn/oBFfWh1lI5Cb7U+GxfszxWZ/9Wp7U8jOAKaNdZq3BsNIXvXPCA1A==
  dependencies:
    "@babel/runtime" "^7.11.2"
    "@contentful/rich-text-react-renderer" "^14.1.1"
    "@contentful/rich-text-types" "^14.1.1"
    "@hapi/joi" "^15.1.1"
    axios "^0.20.0"
    base64-img "^1.0.4"
    bluebird "^3.7.2"
    chalk "^4.1.0"
    contentful "^7.14.7"
    fs-extra "^9.0.1"
    gatsby-core-utils "1.3.23"
    gatsby-plugin-utils "0.2.33"
    gatsby-source-filesystem "2.3.34"
    is-online "^8.5.0"
    json-stringify-safe "^5.0.1"
    lodash "^4.17.20"
    node-fetch "^2.6.1"
    progress "^2.0.3"
    qs "^6.9.4"

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
fracture91commented, Mar 1, 2021

I got this same “Can’t find lockfile entry” error in a slightly different situation. patch-package 6.2.2

I’ve installed a package directly from a github tarball - here’s what it looks like in package.json:

"mdx-prism": "https://github.com/doamatto/mdx-prism/archive/v0.3.2.tar.gz",

That package has an entry in yarn.lock like this:

"mdx-prism@https://github.com/doamatto/mdx-prism/archive/v0.3.2.tar.gz":
  version "0.3.1"
  resolved "https://github.com/doamatto/mdx-prism/archive/v0.3.2.tar.gz#cd4d6240dbd67031f3f8c56304d3dd034e447f25"
  dependencies:
    ...

Note the version "0.3.1" there - the project’s package.json file says the version is 0.3.1+fork.0.1.0: https://github.com/doamatto/mdx-prism/blob/22ca7f91cc3e86096d0ff5bf20cb511ad00b028c/package.json#L3 That mismatch might be a yarn bug? Not sure

Anyway, running yarn run patch-package mdx-prism gives me the same error message as in the OP. I manually changed the version in yarn.lock to "0.3.1+fork.0.1.0" and the error went away, yay! It successfully generates a patch file called mdx-prism+0.3.1+fork.0.1.0.patch.

Unfortunately, I get a version mismatch warning when applying the patch, but it’s good enough for me since everything still works in CI:

Warning: patch-package detected a patch file version mismatch

  Don't worry! This is probably fine. The patch was still applied
  successfully. Here's the deets:

  Patch file created for

    mdx-prism@0.3.1+fork.0.1.0

  applied to

    mdx-prism@0.3.1
  
  At path...

TLDR: make sure the version in yarn.lock matches what’s in the dependency’s package.json and maybe you’ll have better luck with patching

0reactions
viewerwcommented, Sep 19, 2022

try remove node_modules, then npm install

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting errors when patching a npm package - Stack Overflow
The problem here is that you're using two different tools to patch the npm package, and using a different one locally than in...
Read more >
patch-package | Fix broken node modules instantly - YouTube
patch - package is a tool that has saved me a couple of times when I found a bug in an npm package...
Read more >
patch-package - Bountysource
ERROR Failed to apply patch for package react-native at path ... Since NPM version 7, the package-lock.json version 2 file now uses a...
Read more >
Update application dependencies, patch a managed node ...
Install operating system updates. Update the package dependencies of the application. Restart the system. Perform an application-specific health check.
Read more >
Applying a patch in a feature branch - Drupal
The patch command is useful for patches that don't apply, as it will apply most of the patch and then you may be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found