yarn icon indicating copy to clipboard operation
yarn copied to clipboard

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

Open AmrAhmedA opened this issue 1 year ago • 9 comments

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.

AmrAhmedA avatar Apr 23 '23 12:04 AmrAhmedA

Also running into this

navels avatar May 08 '23 17:05 navels

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

AdrianHL avatar Jun 29 '23 07:06 AdrianHL

any solutions ?

TebzaTheMan avatar Jun 29 '23 16:06 TebzaTheMan

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

navels avatar Jun 29 '23 16:06 navels

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.

Kagami avatar Oct 02 '23 16:10 Kagami

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

Which is fine...

RedCore161 avatar Oct 18 '23 20:10 RedCore161

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 avatar Nov 09 '23 11:11 bashaus

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.

bashaus avatar Nov 09 '23 12:11 bashaus

@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.

gabrielschulhof avatar Jun 17 '24 22:06 gabrielschulhof