sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.21k stars 420 forks source link

Peer deps issue when running `npx sanity init` in fresh nextjs app #7009

Open ChrisLaRocque opened 3 months ago

ChrisLaRocque commented 3 months ago

Describe the bug

Running npx sanity init in a clean NextJS app fails due to a peer deps issue with next-sanity. Running npm i next-sanity after the failure works. To Reproduce

Steps to reproduce the behavior:

  1. Run npx create-next-app@latest (all default options)
  2. Run npx sanity init (all default options besides the 'app router' option)
  3. Install should throw an error:
    
    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE could not resolve
    npm ERR! 
    npm ERR! While resolving: mdx-to-portable-text@0.1.0
    npm ERR! Found: @sanity/icons@3.2.0
    npm ERR! node_modules/@sanity/icons
    npm ERR!   @sanity/icons@"^3.2.0" from @sanity/insert-menu@1.0.6
    npm ERR!   node_modules/@sanity/insert-menu
    npm ERR!     @sanity/insert-menu@"1.0.6" from sanity@3.47.1
    npm ERR!     node_modules/sanity
    npm ERR!       sanity@"^3.47.1" from the root project
    npm ERR!   @sanity/icons@"^3.2.0" from @sanity/presentation@1.16.0
    npm ERR!   node_modules/@sanity/presentation
    npm ERR!     @sanity/presentation@"1.16.0" from sanity@3.47.1
    npm ERR!     node_modules/sanity
    npm ERR!       sanity@"^3.47.1" from the root project
    npm ERR!   3 more (@sanity/ui, @sanity/vision, sanity)
    npm ERR! 
    npm ERR! Could not resolve dependency:
    npm ERR! next-sanity@"7" from the root project
    npm ERR! 
    npm ERR! Conflicting peer dependency: @sanity/icons@2.11.8
    npm ERR! node_modules/@sanity/icons
    npm ERR!   peer @sanity/icons@"^2.8" from next-sanity@7.1.4
    npm ERR!   node_modules/next-sanity
    npm ERR!     next-sanity@"7" 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! 
    npm ERR! For a full report see:
    npm ERR! /Users/chrislarocque/.npm/_logs/2024-06-22T15_24_14_848Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/chrislarocque/.npm/_logs/2024-06-22T15_24_14_848Z-debug-0.log

Error: Command failed with exit code 1 (EPERM): npm install next-sanity@7 at makeError$1 (~/.nvm/versions/node/v18.18.2/lib/node_modules/sanity/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:18060:32) at ~/.nvm/versions/node/v18.18.2/lib/node_modules/sanity/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:18409:29 at async initSanity (~/.nvm/versions/node/v18.18.2/lib/node_modules/sanity/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44801:24)


**Expected behavior**

Install succeeds

**Which versions of Sanity are you using?**

@sanity/cli (global) 3.47.1 (up to date) @sanity/image-url 1.0.2 (up to date) @sanity/vision 3.47.1 (up to date) sanity 3.47.1 (up to date)


**What operating system are you using?**
OSX
**Which versions of Node.js / npm are you running?**

9.8.1 v18.18.2

LushawnDev commented 2 months ago

Were you able to find a fix for this? I have similar issues using Sanity 3.52.2 where I get Could not resolve dependency unless I use --legacy-peer-deps whenever I run any npm install or update commands.

I also think it is causing an issue with the pt-string plugin.

Here is my package.json for reference if this issue gets looked into:

{
  "name": "backend",
  "private": true,
  "version": "1.0.0",
  "main": "package.json",
  "license": "UNLICENSED",
  "scripts": {
    "dev": "sanity dev",
    "start": "sanity start",
    "build": "sanity build",
    "deploy": "sanity deploy",
    "deploy-graphql": "sanity graphql deploy"
  },
  "keywords": [
    "sanity"
  ],
  "dependencies": {
    "@sanity/dashboard": "^3.1.4",
    "@sanity/types": "^3.30.1",
    "@sanity/vision": "^3.52.2",
    "get-youtube-id": "^1.0.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-is": "^18.2.0",
    "react-lite-youtube-embed": "^2.3.52",
    "sanity": "^3.52.2",
    "sanity-plugin-dashboard-widget-netlify": "^2.0.1",
    "sanity-plugin-media": "^2.0.5",
    "sanity-plugin-netlify": "^1.1.0",
    "sanity-plugin-pt-string": "^0.0.5",
    "styled-components": "^6.1.12"
  },
  "devDependencies": {
    "@sanity/eslint-config-studio": "^2.0.1",
    "@types/react": "^18.0.25",
    "@types/styled-components": "^5.1.26",
    "eslint": "^8.6.0",
    "prettier": "^2.8.8",
    "typescript": "^4.9.5"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100,
    "bracketSpacing": false,
    "singleQuote": true
  }
}