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

patch-package 6.2.2 • Creating temporary folder SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile #272

Open
yashirooooo opened this issue Oct 13, 2020 · 15 comments · May be fixed by #507

Comments

@yashirooooo
Copy link

No description provided.

@gabrielbull
Copy link

Are you using Yarn 2?

@AaronJPA
Copy link

Are you using Yarn 2?

I am.

and I'm also dealing with the same error here

@gabrielbull
Copy link

gabrielbull commented Nov 20, 2020

patch-package does not yet work with yarn 2 for creating patch files but will work for patching on install. What I do is I use yarn 1 to create the patch file and then you can use yarn 2 normally.

@AaronJPA
Copy link

patch-package does not yet work with yarn 2 for creating patch files but will work for patching on install. What I do is I use yarn 1 to create the patch file and then you can use yarn 2 normally.

thanks!

is it possible to call yarn 1 from within a yarn 2 project?

@gabrielbull
Copy link

gabrielbull commented Nov 21, 2020

No it's not. An "easy" way would be something like this:

mkdir tmp 
cd tmp 
yarn init -y
yarn add dep-name-goes-here

Make your changes inside node_modules.

npx patch-package dep-name-goes-here

And copy over the patch file.

@AaronJPA
Copy link

No it's not. An "easy" way would be something like this:

mkdir tmp 
cd tmp 
yarn init -y
yarn add dep-name-goes-here

Make your changes inside node_modules.

npx patch-package dep-name-goes-here

And copy over the patch file.

got it! thanks!

Venryx added a commit to Venryx/web-vcore that referenced this issue Aug 7, 2021
…rn 2 not yet supported for patch-creation, so used workaround here: ds300/patch-package#272 (comment))
@rxliuli
Copy link

rxliuli commented Aug 30, 2021

Are you using Yarn 2?

why?

@punndcoder28
Copy link

Hi. Just faced this issue on yarn v3.0.2. Followed @gabrielbull solution to get it successfully working thanks! Can we expect a fix for this to support newer version of yarn as well?

@hos
Copy link

hos commented Oct 16, 2021

@punndcoder28 I think you don't need patch-package with yarn v3. You can use yarn patch and yarn patch-commit to achieve same result.

First run yarn patch which will create temp folder where you can edit module. Then when you done run yarn patch-commit and yarn will create a patch for you.

⚠️ Also in my case I had to change patch version in package.json > resolution manually to match with dependency version.
Here is an example repo

ppark2ya pushed a commit to nolmungshemung/writing-hub that referenced this issue Jan 18, 2022
faker를 빌드할 때 export = faker; 구문에서 에러가 나서 라이브러리 수정 후 patch-package로 해결
yarn berry에서 patch-package가 제대로 실행이 되지않아서 하기 이슈 참고하여 해결
- npm 기반 프로젝트에서 patch-package 실행 후 patch 파일 옮겨서 진행
- ds300/patch-package#272

ref #29
ppark2ya pushed a commit to nolmungshemung/writing-hub that referenced this issue Jan 18, 2022
faker를 빌드할 때 export = faker; 구문에서 에러가 나서 라이브러리 수정 후 patch-package로 해결
yarn berry에서 patch-package가 제대로 실행이 되지않아서 하기 이슈 참고하여 해결
- npm 기반 프로젝트에서 patch-package 실행 후 patch 파일 옮겨서 진행
- ds300/patch-package#272

ref #29
@jesstelford
Copy link

jesstelford commented Jun 8, 2022

@hos's method works great, with one caveat: yarn doesn't seem to warn you if your patch is no longer being applied, or your "resolutions" are miss-configured. In these cases, it will silently ignore the patch and continue with regular installation.

Unlike patch-package which will loudly fail installation if your patch can't be applied.

This was enough to waste half a day for me, and force me to switch back to patch-package using @gabrielbull's method.

Edit: the specific failure case I ran into was using yarn berry + node_modules linker, then the package I patched had a new version released (minor), and so the resolutions stopped matching and the patch was silently ignored. But I didn't realise that for many frustrating hours. Whereas when the versions mismatch in patch-package, it fails loudly and immediately when installing deps.

@v4dkou
Copy link

v4dkou commented Jun 21, 2022

Here's a script that automates @gabrielbull's method to the point it's the same as using patch-package with yarn v1.

mkdir tmp
cd tmp
npm init -y
npm install --save "$1"
rsync -av --exclude "node_modules" --delete "../node_modules/$1/" "./node_modules/$1/"
npx patch-package "$1"
mkdir -p ../patches
mv ./patches/* ../patches/
cd ..
rm -rf tmp

Save it as patch-package.sh to the root of your project and run chmod +x ./patch-package.sh (alternatively, call the script with sh)
Then you can run it like this:
./patch-package.sh dep-name-goes-here

This way you can test your changes of the dependency in the project you're using this dependency and then save the patch with a one-liner, just like before.

There's probably a way to save this script and alias it globally, but I am OK with how it turned out already, so I'll leave it for someone else

P.S. this solution might seem a bit crude compared to switching to yarn patch, but I agree with @jesstelford's reasoning for using patch-package instead, silent errors are the worst time wasters.

@v4dkou
Copy link

v4dkou commented Jun 21, 2022

Also, for anyone wishing to use patch-package with yarn berry (v2+), here's a plugin that allows to run patch-package on postinstall

https://github.com/GravitywellUK/yarn-plugin-postinstall

@landsman
Copy link

I have the same issue with Yarn 3.2.0.

unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 2, 2022
- https://github.com/ds300/patch-package/tree/v6.4.7
- ds300/patch-package#272

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 5, 2022
- yarn patch-commit is used to generate patches. patch-package can not be used to apply those patches on install due to directory mismatches (e.g. a/index.js vs a/node_modules/globby/index.js). patches cannot be created with patch-package either
- ds300/patch-package#272
- https://git-scm.com/docs/git-apply
- https://yarnpkg.com/cli/patch-commit
- https://yarnpkg.com/cli/patch

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 5, 2022
- yarn patch-commit is used to generate patches. patch-package cannot be used to apply those patches on install due to directory mismatches (e.g. a/index.js vs a/node_modules/globby/index.js). patches cannot be created with patch-package either
- ds300/patch-package#272
- https://git-scm.com/docs/git-apply
- https://yarnpkg.com/cli/patch-commit
- https://yarnpkg.com/cli/patch

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 5, 2022
- yarn patch-commit is used to generate patches. patch-package cannot be used to apply those patches on install due to directory mismatches (e.g. a/index.js vs a/node_modules/globby/index.js)
- ds300/patch-package#272
- https://git-scm.com/docs/git-apply
- https://yarnpkg.com/cli/patch-commit

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 5, 2022
- yarn patch-commit is used to generate patches. patch-package cannot be used to apply those patches on install due to directory mismatches (e.g. a/index.js vs a/node_modules/globby/index.js)
- ds300/patch-package#272
- https://git-scm.com/docs/git-apply
- https://yarnpkg.com/cli/patch-commit

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
@pistonsky
Copy link

pistonsky commented Dec 20, 2022

I ended up checking out from a commit in my project where I used yarn v1, updated patch there, stashed it, and then checked back where I was before and committed my patch there, popping it from stash.

Couldn't find a way to easily transfer my old patch-package patches to yarn v3 format.

JounQin added a commit to un-ts/patch-package that referenced this issue Dec 21, 2023
@JounQin JounQin linked a pull request Dec 21, 2023 that will close this issue
JounQin added a commit to un-ts/patch-package that referenced this issue Dec 21, 2023
@JounQin
Copy link

JounQin commented Jan 6, 2024

I've just publish my PR #507 as @unts/patch-package, you can give it a try.

jdalton pushed a commit to jdalton/patch-package that referenced this issue Jun 18, 2024
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

Successfully merging a pull request may close this issue.