Home > OS >  Same exact package.json file works in empty brand new project but doesn't in old project
Same exact package.json file works in empty brand new project but doesn't in old project

Time:10-06

I get this error when I try to upgrade to Angular 8.

npm WARN old lockfile

npm WARN old lockfile The package-lock.json file was created with an old version of npm,

npm WARN old lockfile so supplemental metadata must be fetched from the registry.

npm WARN old lockfile

npm WARN old lockfile This is a one-time fix-up, please be patient...

npm WARN old lockfile

npm ERR! code ERESOLVE

npm ERR! ERESOLVE could not resolve

npm ERR!

npm ERR! While resolving: [email protected]

npm ERR! Found: @angular/[email protected]

npm ERR! node_modules/@angular/animations

npm ERR! @angular/animations@"~8.2.14" from the root project

npm ERR! peer @angular/animations@">=7.0.0" from @angular/[email protected]

npm ERR! node_modules/@angular/material

npm ERR! @angular/material@"~8.2.3" from the root project

npm ERR!

npm ERR! Could not resolve dependency:

npm ERR! @angular/animations@"~8.2.14" from the root project

npm ERR!

npm ERR! Conflicting peer dependency: @angular/[email protected]

npm ERR! node_modules/@angular/core

npm ERR! peer @angular/core@"8.2.14" from @angular/[email protected]

npm ERR! node_modules/@angular/animations

npm ERR! @angular/animations@"~8.2.14" from the root project

npm ERR!

npm ERR! Fix the upstream dependency conflict, or retry

npm ERR! this command with --force, or --legacy-peer-deps

npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

npm ERR!

npm ERR! See C:\Users\vakkinen\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:

npm ERR!
C:\Users\vakkinen\AppData\Local\npm-cache_logs\2021-10-05T12_19_50_257Z-debug.log

So decided to create a brand new Angular8 app and see what the package.json file looks like. That file is attached below. Then I added all the packages I need to this brand new empty project one at a time. The application build succeeded and I was able to run the application. So I copied and pasted all the dependencies and devDependencies to the old project package.json. That project still fails npm i because of the same error above. So I tried to clone the repo into a new directory and replaced the contents of the package.json with the contents of the package.json from the brand new empty project, still the same error. What am I doing wrong ?

{
  "name": "dashboard",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/cdk": "8.2.3",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "~8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ng-bootstrap/ng-bootstrap": "^5.3.0",
    "bootstrap": "^4.3.1",
    "core-js": "^2.5.4",
    "@swimlane/ngx-charts": "^11.0.0",
    "fusioncharts": "^3.15.0-sr.1",
    "hammerjs": "^2.0.8",
    "moment": "^2.24.0",
    "ngx-bootstrap": "^3.2.0",
    "ngx-csv": "^0.3.1",
    "ngx-export-as": "1.4.2",
    "ngx-scrollbar": "^4.1.1",
    "ngx-select-dropdown": "^1.0.1",
    "node-sass": "^4.14.0",
    "rxjs": "~6.4.0",
    "sass-loader": "^8.0.2",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",    
    "@angular/cli": "~8.3.29",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.7.0",
    "protractor": "~7.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

CodePudding user response:

There should be a file called package-lock in the same folder as the package file. Delete it and the error should go away. The package-lock file contains all dependencies of your dependencies and their versions. Deleting it doesn’t affect your project since it’s regenerated on npm install.

CodePudding user response:

The error message warns you that the package-lock.json file is the issue. Just delete it and a new one will be generated.

CodePudding user response:

The issue stems from having incorrect files in the node_modules directory and the package-lock.json.

Most probably the easiest solution is to delete both the node_modules directory and the package-lock.json and then running a npm install to get a clean node_modules directory and a new package-lock.json according to your package.json

I recommend reading more about what the package-lock.json file is for here: https://medium.com/coinmonks/everything-you-wanted-to-know-about-package-lock-json-b81911aa8ab8

CodePudding user response:

Steps to fix this issue:

  1. Delete node_modules folder.
  2. Delete package-lock.json.
  3. Run npm i --force.
  • Related