Skip to content

[Bug] TypeScript Create React App projects do not work within workspaces. #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
DylanVann opened this issue Feb 2, 2020 · 9 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@DylanVann
Copy link

DylanVann commented Feb 2, 2020

  • I'd be willing to implement a fix

More of a maybe on that. I have no idea why this bug occurs. If I get some hint I could possibly help with implementing a fix. The types for jest are installed, so I'm not sure why they cannot be found.

Describe the bug

image

Failed to compile.

undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'jest'.  TS2688

To Reproduce

  • Create a workspaces project.
  • Create a CRA app within packages. e.g. create-react-app app --template typescript --pnp
    • I'm not sure the --pnp flag does anything.
    • At this point I delete yarn.lock within app, as well as the pnp file.
  • Try to run start for the app. e.g. yarn workspace app start

Here's a repo: https://github.com/DylanVann/yarn-berry-create-react-app-bug

Environment if relevant (please complete the following information):

  • OS: macOS 10.15.2
  • Node: v13.7.0
  • Yarn: v2.0.0-rc.28
@DylanVann DylanVann added the bug Something isn't working label Feb 2, 2020
@sjmeverett
Copy link

I'd just like to add that a similar thing happens for me not in a workspace project, so it might be a red herring that it has anything to do with workspaces.

i.e. I run this:

~/Code $ yarn dlx create-react-app app --template typescript --pnp
~/Code $ cd app
~/Code/app $ yarn start

And I get this:

Failed to compile.

undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'color-name'.  TS2688

Versions:

  • MacOS Catalina: 10.15.1
  • Node: v12.7.0
  • Yarn: 2.0.0-rc.27
  • create-react-app: 3.3.1

@haydnhkim
Copy link

It also happens in next.js using typescript.
If yarn2 doesn't use a workspace, that's fine. but if I make it a workspace, next build won't work.

root package.json

{
  ...
  "workspaces": [
    "packages/*"
  ],
  "scripts": {
    "build": "yarn workspace dev-test-next-app build",
  }
}

packages/app/package.json

{
  ...
  "name": "dev-test-next-app",
  "scripts": {
    "build": "next build"
  }
}

result:

$ yarn build
Creating an optimized production build

Failed to compile.

ERROR in undefined(undefined,undefined):
undefined:undefined Cannot find type definition file for 'node'.

> Build error occurred
Error: > Build failed because of webpack errors
    at build (/Users/haydn/Documents/test/next-app/.yarn/$$virtual/next-virtual-c45165e61c/0/cache/next-npm-9.2.1-9e2a04bc32-1.zip/node_modules/next/dist/build/index.js:10:900)

versions:

  • MacOS Mojave: 10.14.6
  • Node: v12.14.1
  • Yarn: 2.0.0-rc.27
  • next: 9.2.1

@chrislambe
Copy link

chrislambe commented Feb 13, 2020

Same issue here. Yarn 2 monorepo with PnP, trying to yarn start a CRA project.

$ yarn workspace foo start
Failed to compile.

undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'flat'.  TS2688

Versions:

  • macOS Catalina: 10.15.2
  • Node: v10.16.0
  • Yarn: 2.0.0-rc.29
  • CRA (react-scripts): 3.3.1

@Felix-Indoing
Copy link

Felix-Indoing commented Feb 28, 2020

CRA version 3.4.0 with typescript in yarn 2 workspaces when execute yarn workspace foo start procude the following:

Failed to compile.

./src/App.tsx
Module not found: Something that got detected as your top-level application (because it doesn't seem to belong to any package) tried to access a package that is not declared in your dependencies

@jacogr
Copy link

jacogr commented Mar 4, 2020

At least in my case removing typeRoots from the tsconfig.json solves the issue. (Which is not great in all cases since there are custom types that are published in a seperate repo)

I believe the "typeRoots": ["./node_modules/@types", ...] does not quite what it as intended to do here, possibly due to the ./node_modules included there.

YYMV, played around it and removing the roots solved the issue for me with @types/jest, however sadly this is not really a solution I can apply to all my repos.

@arcanis
Copy link
Member

arcanis commented Mar 26, 2020

I didn't manage to reproduce your issues (even following your repros :(), but @ucarion provided one lately which had the same error: https://github.com/ucarion/berry-next-typescript-repro

Thanks to this, I've just released a fix in ts-pnp which I think should also fix any similar problem. If that's not the case, please reopen an issue and 🙏🙏🙏 make sure the repro is as simple as possible so that we can get straight to the fix 🙂

(Note: to use the ts-pnp fix: open your lockfile, remove the ts-pnp entries, then run yarn install)

@arcanis arcanis closed this as completed Mar 26, 2020
@sjmeverett
Copy link

sjmeverett commented Apr 8, 2020

Hi @arcanis, thanks for your work on this. Unfortunately I've still got a problem, please see https://github.com/sjmeverett/berry-react-app for a repro.

I can confirm it works for a simple project now though 👍 it's just workspaces that cause a problem.

@sjmeverett
Copy link

sjmeverett commented Apr 8, 2020

Actually I've found the problem. react-scripts depends on a specific version of ts-pnp, which doesn't include the fix.

This will get it to work for now (in .yarnrc.yml):

packageExtensions:
  react-scripts@*:
    dependencies:
      ts-pnp: "^1.2.0"

And you may also need to delete the ts-pnp entries in your yarn.lock

@yashafromrussia
Copy link

I was able to reproduce this when the repo was in ~/Documents/repo_name (on a mac). ~/Documents get synced to iCloud. Disabling syncing Documents to iCloud or moving the repo to another directory that's not being synced to iCloud resolved the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants