yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.37k stars 2.72k forks source link

error Failed to import from package-lock.json, source file(s) corrupted #8943

Open AmrAhmedA opened 1 year ago

AmrAhmedA commented 1 year ago

I was trying to use your yarn import command to generate yarn.lock file in npm package, the package lock does exist. package-lock.json

$ yarn import 
yarn import v1.22.19
info found npm package-lock.json, converting to yarn.lock
error Failed to import from package-lock.json, source file(s) corrupted
info Visit https://yarnpkg.com/en/docs/cli/import for documentation about this command.

I've reinstalled the dependencies. still I encounter the same problem.

navels commented 1 year ago

Also running into this

AdrianHL commented 1 year ago

Just tried to use yarn import and got into the same problem here.

TebzaTheMan commented 1 year ago

any solutions ?

navels commented 1 year ago

Not the greatest answer but we ended up switching to pnpm and haven't looked back ;-)

Kagami commented 9 months ago

Same issue. Basically you can't properly migrate from npm to yarn at the moment because lock file import doesn't work. If you just run yarn install it will install different dependencies.

Not a huge deal because we have semver but still annoying.

RedCore161 commented 8 months ago

Deleting package-lock.json works for me. It now says: "info creating yarn.lock from local node_modules folder"

Which is fine...

bashaus commented 7 months ago

I found out that this is caused by a dependency:

"@isaacs/cliui@^8.0.2":
  version "8.0.2"
  resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
  integrity sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==
  dependencies:
    string-width "^5.1.2"
    string-width-cjs "npm:string-width@^4.2.0"
    strip-ansi "^7.0.1"
    strip-ansi-cjs "npm:strip-ansi@^6.0.1"
    wrap-ansi "^8.1.0"
    wrap-ansi-cjs "npm:wrap-ansi@^7.0.0"
    "node_modules/@isaacs/cliui": {
      "version": "8.0.2",
      "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
      "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==",
      "license": "ISC",
      "dependencies": {
        "string-width": "^5.1.2",
        "string-width-cjs": "npm:string-width@^4.2.0",
        "strip-ansi": "^7.0.1",
        "strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
        "wrap-ansi": "^8.1.0",
        "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },

specifically the version numbers which prefix with npm: (e.g.: npm:string-width@^4.2.0).

Unfortunately no resolution - anyone else run in to this?

bashaus commented 7 months ago

Funny enough, the resolution was resolutions. In your package.json, add a resolutions field:

  "resolutions": {
    "string-width": "^5.1.2",
    "strip-ansi": "^7.0.1",
    "wrap-ansi": "^8.1.0"
  }

Your problem may not be with string-width, strip-ansi and wrap-ansi - but the solution may be to search your package-lock.json and find where npm: is being used and write resolutions for it.

gabrielschulhof commented 1 week ago

@bashaus I had the same three packages prefixed with npm: but adding them to resolutions didn't help. yarn import still fails by saying that package-lock.json is corrupt.