7

Hey When I am running npm install and my package lock file is being generated it is building the file in a weird structure. Now I have checked with our other developers to try and simulate this on the same branches and they don't get the same issues. So this must be a problem local to me.

I did recently update node however I am running the same node version as the other devs and they don't get the issue.

node version - 14.17.3 npm version - 7.20.1

I thought it could be a node issue at first but we are on the same version. I have tried removing node_modules and the json lock and performing a new npm i but get the same issue.

When running npm run bundle it seems to build ok but the file structure looks strange to me and it has doubled in line size. I cant put the entire contents of the file here as its over 50,000 lines long. But i can give you a snapshot of how the file starts from how it should look to how it is now.

enter image description here

Before:

  {
  "name": "@culture-trip/header-ui-module",
  "version": "8.12.11",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "@babel/code-frame": {
      "version": "7.12.13",
      "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
      "integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==",
      "dev": true,
      "requires": {
        "@babel/highlight": "^7.12.13"
      }
    },
    "@babel/compat-data": {
      "version": "7.13.8",
      "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.13.8.tgz",
      "integrity": "sha512-EaI33z19T4qN3xLXsGf48M2cDqa6ei9tPZlfLdb2HC+e/cFtREiRd8hdSqDbwdLB0/+gLwqJmCYASH0z2bUdog==",
      "dev": true
    },

After:

{
  "name": "@culture-trip/header-ui-module",
  "version": "8.12.11",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "": {
      "name": "@culture-trip/header-ui-module",
      "version": "8.12.11",
      "license": "TCT",
      "dependencies": {
        "axios": "^0.21.1",
        "js-cookie": "^2.2.1",
        "lodash.debounce": "^4.0.8",
        "react-autocomplete": "github:culture-trip/react-autocomplete#415ebd07c1b5a9037513a76d82d6e0fa54b7fc50",
        "react-router-dom": "^5.2.0"
      },

As you can see the actual structure has changed. Im really not sure whats going on here so hopping someone can help.

ashley g
  • 857
  • 3
  • 11
  • 21

2 Answers2

6

Your package-lock.json file is using lockfileVersion: 2 it has likely changed since you updated from an older npm version.

"lockfileVersion": 2,

The new file is flattened to increase performance when reading and writing. this inadvertently makes the file much longer.

If you want to continue using the old version of lockfile you could downgrade your npm version to anything below 7.

More on the package-lock.json file.

Edit: You don't have to downgrade npm see Vadim's answer.

lejlun
  • 4,140
  • 2
  • 15
  • 31
4

You don't have to downgrade your npm, you can keep the old package-lock.json format by using the --lockfile-version flag

In your case

npm i --lockfile-version 1

will work.

Sergey
  • 1,608
  • 1
  • 27
  • 40
Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90