ds300 / patch-package

Fix broken node modules instantly 🏃🏽‍♀️💨
MIT License
10.36k stars 290 forks source link

** Error ** Unknown token: { line: 4, col: 2, type: 'INVALID', value: undefined } 4:2 in lockfile #407

Open admin8756 opened 2 years ago

admin8756 commented 2 years ago

image

I was trying to modify the elementui. Remind me of this error

landsman commented 2 years ago

I have a smillar issue as well:

SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile
% yarn --version
3.2.0
admin8756 commented 2 years ago

I have a smillar issue as well:

SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile
% yarn --version
3.2.0

Our questions seem to be the same, but the author has not updated them for two years

erick-martins commented 2 years ago

We have the same issue with yarn 2. It's so frustrating that we had to create an work around script to deal with it

Here it is if it would help someone:

#!/usr/bin/env bash
set -e

root="${PWD}"

# Package name and current version
package_name="$1"
version=$(yarn why "${package_name}" | grep -o "${package_name}@npm:[^\[]*" | cut -d ":" -f2)

# Create temporary folder
rm -rf "${root}/tmp"
mkdir "${root}/tmp" 
cd "${root}/tmp"

# Creates an empty npm project, install package and copy changes
npm init -y
npm i "${package_name}@${version}" 
cp -a "${root}/node_modules/${package_name}/." "./node_modules/${package_name}/" 

# Creates the patch, moves it to main project and clean up
npx patch-package "${package_name}" 
cp -a ./patches/. "${root}/patches/" 
rm -rf "${root}/tmp"

Then call it like this: scripts/yarn-patch-package package-name

admin8756 commented 2 years ago

We have the same issue with yarn 2. It's so frustrating that we had to create an work around script to deal with it

Here it is if it would help someone:

#!/usr/bin/env bash
set -e

root="${PWD}"

# Package name and current version
package_name="$1"
version=$(yarn why "${package_name}" | grep -o "${package_name}@npm:[^\[]*" | cut -d ":" -f2)

# Create temporary folder
rm -rf "${root}/tmp"
mkdir "${root}/tmp" 
cd "${root}/tmp"

# Creates an empty npm project, install package and copy changes
npm init -y
npm i "${package_name}@${version}" 
cp -a "${root}/node_modules/${package_name}/." "./node_modules/${package_name}/" 

# Creates the patch, moves it to main project and clean up
npx patch-package "${package_name}" 
cp -a ./patches/. "${root}/patches/" 
rm -rf "${root}/tmp"

Then call it like this: scripts/yarn-patch-package package-name

This library has not been updated for a long time. There should be some conflicts with some new features. But I don't have time to deal with it. Your method doesn't look particularly elegant. But it can solve the problem.

jaumereg commented 3 months ago

Upgrading to 8.0.0 and running npx patch-package package-name instead of yarn worked for me