strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable, and developer-first.
https://strapi.io
Other
63.61k stars 8.08k forks source link

Missing dependency for TS projects using pnpm #18781

Open jbhammon opened 11 months ago

jbhammon commented 11 months ago

Bug report

Required System information

Describe the bug

Issue #15992, that Strapi wouldn't work with pnpm, was fixed, but there is still an issue with Typescript projects. When you install dependencies with pnpm you get this error about a missing dependency:

ERROR in ./tsconfig.json
TS6053: File '@strapi/typescript-utils/tsconfigs/server' not found.

The @strapi/typescript-utils package doesn't get installed, but it's referenced in the tsconfig file that the Strapi CLI creates.

Steps to reproduce the behavior

  1. Setup a Strapi project to install dependencies with pnpm
  2. Install dependencies with pnpm i
  3. Run the dev command pnpm develop
  4. See the error about missing typescript utils

Expected behavior

Installing dependencies with pnpm installs the typescript-utils package.

I manually added the dependency, and then the develop script was able to run fine. I'm guessing that a solution could be for the Strapi CLI to add this dependency to the package.json file for TS projects.

Code snippets

As a reference, here's the ./tsconfig file causing the problem:

{
  // Line causing the error
  "extends": "@strapi/typescript-utils/tsconfigs/server",
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true
  },
  "include": ["./", "./**/*.ts", "./**/*.js", "src/**/*.json"],
  "exclude": [
    "node_modules/",
    "build/",
    "dist/",
    ".cache/",
    ".tmp/",
    "src/admin/",
    "**/*.test.*",
    "src/plugins/**"
  ]
}

Additional context

If there are any other TS-specific issues with using pnpm this issue could be a good place to collect them if they're small in scope.

jbhammon commented 11 months ago

@joshuaellis here's an issue for the dependency problem I noted earlier on #15992

I'm happy to take a stab at fixing this if someone can point me in the direction of where to start!

pluveto commented 4 months ago

pnpm add @strapi/typescript-utils

maxdzin commented 2 months ago

There's also another way without installing @strapi/typescript-utils.

  1. Add .npmrc file at the project root with this content:
    shamefully-hoist=true
  2. Remove existing node_modules and pnpm-lock.yml file.
  3. Run pnpm i.
  4. Launch project: pnpm develop.