Skip to content
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

[Bug?]: Cannot find module ... when using tsc #3377

Closed
1 task
andersonkyle opened this issue Sep 2, 2021 · 2 comments
Closed
1 task

[Bug?]: Cannot find module ... when using tsc #3377

andersonkyle opened this issue Sep 2, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@andersonkyle
Copy link

Self-service

  • I'd be willing to implement a fix

Describe the bug

An extremely minimal project that uses Yarn w/ PnP and TypeScript fails to compile due to:

src/index.tsx:1:19 - error TS2307: Cannot find module 'react' or its corresponding type declarations.

1 import React from "react"
                    ~~~~~~~


Found 1 error.

To reproduce

Configuration

.yarnrc.yml

yarnPath: ".yarn/releases/yarn-berry.cjs"

tsconfig.json

{
    "compilerOptions": {
        "jsx": "react"
    }
}

package.json

{
  "name": "typescript-project",
  "packageManager": "[email protected]",
  "scripts": {
    "build": "tsc"
  },
  "devDependencies": {
    "typescript": "^4.4.2"
  },
  "dependencies": {
    "react": "^17.0.2"
  }
}

Code

index.tsx

import React from "react"

const Greeting = () => (<div>Hello, World!</div>)

Command

yarn build

Environment

System:
OS: Ubuntu 20.04 LTS (via WSL on Windows 10 Pro 19042.1202)
CPU: Intel(R) Core(TM) i7-8550U
Binaries:
Node: 14.17.6 - /usr/bin/node
Yarn (global): 1.22.11 - /home/me/.npm-global/bin/yarn
npm: 6.14.15 - /usr/bin/npm

Additional context

Per the documentation TypeScript "natively" supports PnP (by way of a patch) so I'm unsure why this simple application isn't working.

If I enable node_modules by adding this to .yarnrc.yml it all works as expected:

yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: node-modules
@andersonkyle andersonkyle added the bug Something isn't working label Sep 2, 2021
@merceyz
Copy link
Member

merceyz commented Sep 2, 2021

Duplicate of #3350

@merceyz merceyz marked this as a duplicate of #3350 Sep 2, 2021
@merceyz merceyz closed this as completed Sep 2, 2021
@merceyz
Copy link
Member

merceyz commented Sep 2, 2021

The fix is to run the following command

yarn set version canary && yarn

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

2 participants