Error: ": Unexpected token \u0000 in JSON at position 0" when using yarn to add a react package

Viewed 1665

I am trying to install the following package through yarn yarn add react-native-gesture-handler@1.10.2. I read multiple answers to this question yet none was of use. I think the problem might come from the fact I am on a windows computer yet don't know how to solve it.

Whenenever y try to do a yarn add ..@version I get the following error:

yarn add v1.22.11
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is 
advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "C:\\Users\\...\\AppData\\Local\\Yarn\\Cache\\v6\\npm-unbox-primitive-1.0.1-085e215625ec3162574dc8859abee78a59b14471-integrity\\node_modules\\unbox-primitive\\.yarn-metadata.json: 
Unexpected token \u0000 in JSON at position 0".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\...\\OneDrive\\Documents\\GitHub\\wc_app\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
2 Answers

I have same problem with installing next.js app many times now its fixed

with clear cache of yarn

yarn cache clean

I have faced a similar problem while creating a latest react native project(0.65) in my Windows machine:

error An unexpected error occurred: "C:\Users\arefin\AppData\Local\Yarn\Cache\v6\npm-is-ci-3.0.0-c7e7be3c9d8eef7d0fa144390bd1e4b88dc4c994-integrity\node_modules\is-ci\.yarn-metadata.json: Unexpected token \u0000 in JSON at position 0".

My system configuration for react native development is as follows:

  • node --version: v15.7.0
  • yarn --version: 1.22.5
  • npm --version: 7.12.1
  • java --version: java 15.0.2 2021-01-19

I used these commands below, which finally solved the problem in my case:

yarn init && yarn add react-native && yarn react-native init SpendnGain

which I found at here

Related