node.jsnpmyarnpkg

Yarn - Command yarn import error: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions


I'm looking for using yarn and npm together in my project and if I find yarn useful for my particular case, I could move my project to use yarn only.

Nevertheless, I'm getting the following error with $yarn import:

local:project_middleware jgil$ yarn import

Internal Error: project-middleware@workspace:.: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions
at J.getCandidates (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:325115)
at i.getCandidates (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:314232)
at /Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:335605
at Array.map (<anonymous>)
at Ae.resolveEverything (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:335321)
at async Ae.applyLightResolution (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:357937)
at async Ae.restoreInstallState (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:357667)
at async Ke.execute (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:98394)
at async Ke.validateAndExecute (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:626801)
at async j.run (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:17:3854)

I have already run $yarn set version berry and tried out again and again with different combinations of removing the node_modules directory, running npm install, etc. and nothing gets to make it work... no idea of what's missing.

Could it be a problem with either the version of Node.js or any other component I'm using?


Solution

  • The problem in here seems to be an existing yarn.lock file inside of one of the workspaces. Deleting it solves the problem.

    More info:

    Example: 3 workspaces: 2 create-react-app (app, home) and one shared component: (components)

    folder strcuture

    Inside the component folder a lingering yarn.lock file exists. Remove it.

    enter image description here

    Also check that:

    1. All your workspaces have "private": true in each of their package.json (same level as name, private, source).
    2. Check that you have added your workspaces inside a "workspaces" key in the main package.json
    3. When you're executing yarn workspaces myworkspace myworkspace matches the name of your workspace in its package.json. In my case, the name of the workspace inside the components folder is called @schon/components, so I need to address it as yarn worksapces @schon/components instead.