create-react-app: yarn pnp doesn't work with typescript

Set up a pnp typescript project npx create-react-app pnp --use-pnp --typescript or npx create-react-app pnp --typescript --use-pnp order doesn’t matter

You then get

yarn add v1.12.1
[1/5] πŸ”  Resolving packages...
[2/5] 🚚  Fetching packages...
[3/5] πŸ”—  Linking dependencies...
[5/5] πŸ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
info Direct dependencies
β”œβ”€ @types/jest@23.3.9
β”œβ”€ @types/node@10.12.1
β”œβ”€ @types/react-dom@16.0.9
β”œβ”€ @types/react@16.4.18
β”œβ”€ react-dom@16.6.0
β”œβ”€ react-scripts@2.1.0
β”œβ”€ react@16.6.0
└─ typescript@3.1.4
info All dependencies
β”œβ”€ @types/jest@23.3.9
β”œβ”€ @types/node@10.12.1
β”œβ”€ @types/react-dom@16.0.9
β”œβ”€ @types/react@16.4.18
β”œβ”€ react-dom@16.6.0
β”œβ”€ react-scripts@2.1.0
β”œβ”€ react@16.6.0
└─ typescript@3.1.4
✨  Done in 14.72s.
We detected TypeScript in your project (src/App.test.tsx) and created a tsconfig.json file for you.

It looks like you're trying to use TypeScript but do not have typescript installed.
Please install typescript by running yarn add typescript.
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).


Aborting installation.
  node --require /Users/bond/Projects/pnp-test/.pnp.js has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Done.

Environment


  System:
    OS: macOS 10.14
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 8.12.0 - /usr/local/bin/node
    Yarn: 1.12.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  npmGlobalPackages:
    create-react-app: Not Found

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 41
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I found the time and pushed a PR: https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/250

Once merged I’ll make another one to create-react-app to upgrade fork-ts-checker-webpack-plugin and add support for the resolvers πŸ™‚

PR up at #6856

This works but is needlessly complicated:

  1. Get yarn 2., Go to empty directory
yarn set version berry
yarn dlx create-react-app --template typescript my-app
cd my-app
yarn add @yarnpkg/pnpify -D
yarn pnpify --sdk
// Open with vscode
// Go to currently broken tsx file
// Hit Ctrl+Shift+P, choose select Typescript version -> Use Workspace Version Pnipify
// Reload Vscode window
// Finally you might want to remove extra files from the root 
// Then run `yarn set version berry` in my-app too

@alaatm I’ve got similar error when I run yarn create react-app another-app --typescript --use-pnp. I’ve run yarn create react-app another-app --typescript instead and then yarn --pnp. Then I’ve got exactly the same error so I run yarn install. Did not helped so I run it again as I was expecting to see success Already up-to-date but it seems that with pnp it always go through all the steps. This made yarn run start run. There were any changes to yarn.lock nor .pnp.js files. Now yarn create react-app another-app --typescript --use-pnp works too and I could not reproduce the issue anymore.

TL;DR; Run yarn install twice. πŸ˜ƒ

Updating workaround from @Ciantic …

yarn set version berry
yarn dlx create-react-app --template typescript my-app
cd my-app
yarn add @yarnpkg/pnpify -D
yarn dlx @yarnpkg/sdks vscode

VSCode seems to use the workspace sdk when β€œtypescript.tsdk” is set appropriately

# file: .vscode/settings.json
{
  "search.exclude": {
    "**/.yarn": true,
    "**/.pnp.*": true
  },
  "typescript.tsdk": ".yarn/sdks/typescript/lib",
  "typescript.enablePromptUseWorkspaceTsdk": true
}

I’m still getting this issue. When I try using @Ciantic’s workaround, I get #10002 instead. I’m kind of at a loss for words; regardless of which version of yarn I use or how I invoke the various commands, yarn+pnp+typescript really doesn’t want to work with create-react-app for me.

Is this in 3.0.1? It says it is in the release notes but the error is still there.

yarn run v1.16.0
$ react-scripts start
C:\personal-projs\we-there-yet-qm\.pnp.js:15914
    throw firstError;
    ^Error: Cannot find module 'react-dev-utils/crossSpawn'
Require stack:
- C:\Users\alaam\AppData\Local\Yarn\cache\v4\npm-react-scripts-3.0.1-e5565350d8069cc9966b5998d3fe3befe3d243ac\node_modules\react-scripts\bin\react-scripts.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
    at Function.Module._resolveFilename (C:\personal-projs\we-there-yet-qm\.pnp.js:15871:44)
    at callNativeResolution (C:\personal-projs\we-there-yet-qm\.pnp.js:15476:19)
    at Object.resolveToUnqualified (C:\personal-projs\we-there-yet-qm\.pnp.js:15593:22)
    at Object.resolveRequest (C:\personal-projs\we-there-yet-qm\.pnp.js:15723:31)
    at Function.Module._resolveFilename (C:\personal-projs\we-there-yet-qm\.pnp.js:15905:30)
    at Function.Module._load (C:\personal-projs\we-there-yet-qm\.pnp.js:15821:31)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (C:\Users\alaam\AppData\Local\Yarn\cache\v4\npm-react-scripts-3.0.1-e5565350d8069cc9966b5998d3fe3befe3d243ac\node_modules\react-scripts\bin\react-scripts.js:18:15)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Any chance of seeing this land on 3.0 ? This would be really helpful, my team is getting depressed because of the long install times on our monorepo…