Yarn errors when running slicemachine

I am getting the following error when trying to run yarn slicemachine on a yarn based monorepo we are using.

Error: io-ts-types tried to access newtype-ts (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Required package: newtype-ts
Required by: io-ts-types@virtual:e1cebf8a635d6e3a2fd6372619b85b12c19b0c48ba6bac7c33e9a9f11d5d7bf2fd7e359d2bebcec273de205f3556ae16cd5d02b7433711e724be20ead6b68a01#npm:0.5.16 (via /Users/frank.stallone/klaviyo/fender/.yarn/__virtual__/io-ts-types-virtual-61a16193b9/0/cache/io-ts-types-npm-0.5.16-dc3d2cf03f-39b5c5639d.zip/node_modules/io-ts-types/lib/)

Ancestor breaking the chain: @prismicio/types-internal@virtual:e1cebf8a635d6e3a2fd6372619b85b12c19b0c48ba6bac7c33e9a9f11d5d7bf2fd7e359d2bebcec273de205f3556ae16cd5d02b7433711e724be20ead6b68a01#npm:0.2.11
Ancestor breaking the chain: @slicemachine/core@npm:1.1.12

Is this a peerDependency issue with Prismic packages?

This is a Next.js app. Here is the package.json:

{
  "name": "super-awesome-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "slicemachine": "start-slicemachine"
  },
  "dependencies": {
    "@prismicio/slice-simulator-react": "^0.2.2",
    "next": "12.2.4",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@prismicio/client": "^6.6.4",
    "@prismicio/helpers": "^2.3.3",
    "@prismicio/next": "^0.1.3",
    "@prismicio/react": "^2.4.4",
    "@prismicio/types": "^0.2.1",
    "eslint": "8.20.0",
    "eslint-config-next": "12.2.3",
    "prismic-ts-codegen": "^0.1.2",
    "slice-machine-ui": "^0.4.2"
  }
}

Hi @frank.stallone

Thanks for reaching out.

So as you are using Yarn’s Plug’n’Play feature which forces packages to list your dependencies correctly.
@slicemachine/core lists @newtype-ts as a dependency, which needs @monocle-ts and @newtype-ts, but @slicemachine/core does not provide them.

To fix this issue, @slice-machine-team you can, for example, add @monocle-ts and @newtype-ts to your dependencies or convert these to peerDependencies (which would require you to add these to your package.json — which maybe is not a good DX).

In the meantime, you can use Yarn’s packageExtensions config to patch @slicemachine/core by adding these lines to your .yarnrc.yml file such as :

packageExtensions: "@slicemachine/core@*": dependencies: monocle-ts: "" newtype-ts: ""

@Fares thank you for your response! Yes, this is the feature we were using. I was trying to figure out the right packageExtensions to add but could not get them right. Reading the docs for packageExtensions and the error left me without a clear picture of what I needed to add. For instance, (if you don't mind me asking) how did you discover @newtype-ts needed @moocle-ts? Here was my last attempt but was still failing:

  '@slice-machine/core@*':
    peerDependencies:
      newtype-ts: 0.3.5

Hmm. Okay this is where I am lost. I tried both of the following...

  '@slice-machine/core@*':
    dependencies:
      monocle-ts: 2.3.13
      newtype-ts: 0.3.5

... and

  '@slice-machine/core@*':
    dependencies:
      monocle-ts: ""
      newtype-ts: ""

I then ran yarn which gave me

➤ YN0068: │ @slice-machine/core ➤ dependencies ➤ monocle-ts: No matching package in the dependency tree; you may not need this rule anymore.
➤ YN0068: │ @slice-machine/core ➤ dependencies ➤ newtype-ts: No matching package in the dependency tree; you may not need this rule anymore.

... then running yarn slicemachine I still see:

/.../.../.../.../.pnp.cjs:72637
      Error.captureStackTrace(firstError);
            ^

Error: io-ts-types tried to access newtype-ts (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Required package: newtype-ts
Required by: io-ts-types@virtual:e1cebf8a635d6e3a2fd6372619b85b12c19b0c48ba6bac7c33e9a9f11d5d7bf2fd7e359d2bebcec273de205f3556ae16cd5d02b7433711e724be20ead6b68a01#npm:0.5.16 (via /.../.../...//.yarn/__virtual__/io-ts-types-virtual-61a16193b9/0/cache/io-ts-types-npm-0.5.16-dc3d2cf03f-39b5c5639d.zip/node_modules/io-ts-types/lib/)

Ancestor breaking the chain: @prismicio/types-internal@virtual:e1cebf8a635d6e3a2fd6372619b85b12c19b0c48ba6bac7c33e9a9f11d5d7bf2fd7e359d2bebcec273de205f3556ae16cd5d02b7433711e724be20ead6b68a01#npm:0.2.11
Ancestor breaking the chain: @slicemachine/core@npm:1.1.12

Ok, I have forwarded this to our dev team, and they might reach back to you soon.