34

I used the command yarn install in Visual Studio Code, but it ocurred error. following error message.

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.

I think it was overlapped by npm package-lock.json conflict with yarn.lock.

Action against the problem.

remove package-lock.json, remove node_modules

This problem remain unsolved.

thank you!

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
Quack
  • 680
  • 1
  • 8
  • 22
  • before they could operate together: https://yarnpkg.com/blog/2018/06/04/yarn-import-package-lock/ – Carmine Tambascia Jul 22 '19 at 10:30
  • 3
    Came here because I get this message in a new directory, no lock or package files neither in it, nor in (any) parent. – Denis Oct 25 '19 at 16:10
  • For mono repository projects, you can use `find . -name "package-lock.json" -type f -delete` to ensure there are no stray `package-lock.json` files. It can be run first without the `-delete` flag to just show a list of the matching files. – Doug Wilhelm May 18 '20 at 20:40
  • @Denis did you solve the isssue ? – Eren Tüfekçi Dec 03 '20 at 22:01
  • @ErenTüfekçi as I remember I just closed eyes and used some ugly workaround, because it was some not important experiment – Denis Dec 04 '20 at 23:27

10 Answers10

24

I noticed a similar warning today . The issue went off after I deleted package.json file.I had used yarn and npm interchangeable until now in my side project.

'npm install' creates package-lock.json and 'yarn install' generates yarn.lock . Normally you stick to either one of the package managers in your project

Eddie Cooro
  • 1,676
  • 14
  • 18
1nullpointer
  • 1,212
  • 1
  • 13
  • 19
4

Just delete the package-lock.json and you'll be go to go

agoumi
  • 304
  • 5
  • 24
  • I had the same issue coming up so I have just deleted the package-lock.json as the error was raising the same concern and then the issue was resolved. – Iqra. Jun 13 '22 at 13:00
2

The problem arises when you use npm and yarn in the same project, ergo the conflict between yarn.lock and package-lock.json files.

In cases where you only used yarn in your project and still got the same error, chances are that the package files were created in another directory (mostly the root directory) which also happened to have a package-lock.json file. So search for the package name in your file system to know where it was installed and delete the package-lock.json file.

I found that running yarn init in your working directory before running yarn add <package-name> could help with preventing the packages from being installed in another directry and save you some time.

othaimeen
  • 21
  • 2
1

i was also facing same issue. First copy all your angular projects, and delete angular where it install. then install first yarn from brew.sh then install angular cli . it works for me.

P S
  • 7
  • 5
0

Faced same issue. Replaced "RUN yarn install --production" with "RUN npm install --production"

Prem
  • 303
  • 2
  • 9
0

I was running with the same problem multiple times when I tried to add a few dependencies through yarn and nmp. Then I just stopped the localhost server and then installed dependencies using yarn. It worked without any problem.

Ali Razzaq
  • 21
  • 2
0

One good way to avoid this happening is using package-locks-checks.

If you run npx package-locks-checks it will check for this kind of inconsistencies and avoid you to have issues on productions enviroment.

Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
0

i faced the same issue today and solved by deleting the package-lock.json file.

0

# Run this to create-react-app using npm

npx create-react-app my-app

# Or run this to create-react-app using yarn

yarn create react-app my-app

You can follow this question as well . How to make create-react-app use npm instead of yarn

0

I was facing this issue while building on docker, it worked fine before but suddenly started showing this.

I had to replace "RUN yarn" and "CMD yarn start" with "RUN npm install" and "CMD npm start" in my Dockerfile

hasharnashar
  • 113
  • 1
  • 8