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

Error: Required TypeScript & Types packages, despite being installed #36201

Closed
1 task done
ryandotelliott opened this issue Apr 15, 2022 · 12 comments · Fixed by #39838
Closed
1 task done

Error: Required TypeScript & Types packages, despite being installed #36201

ryandotelliott opened this issue Apr 15, 2022 · 12 comments · Fixed by #39838
Labels
bug Issue was opened via the bug report template. please add a complete reproduction Please add a complete reproduction.

Comments

@ryandotelliott
Copy link

ryandotelliott commented Apr 15, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Binaries:
  Node: 16.13.2
  npm: 8.1.2
  Yarn: 1.22.18
  pnpm: N/A
Relevant packages:
  next: 12.1.6-canary.2
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

After running yarn create next-app next-tailwind-typescript-starter --example with-typescript then yarn build, I get the error

Please install typescript, @types/react, and @types/node by running:

yarn add --dev typescript @types/react @types/node

My package.json

{
    "private": true,
    "scripts": {
        "dev": "next",
        "build": "next build",
        "start": "next start",
        "type-check": "tsc"
    },
    "dependencies": {
        "@aws-sdk/client-s3": "^3.67.0",
        "@types/mongodb": "^4.0.7",
        "dotenv": "^16.0.0",
        "formidable": "^3.2.1",
        "mongodb": "^4.5.0",
        "next": "^12.1.6-canary.2",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-icons": "^4.3.1",
        "uniqid": "^5.4.0"
    },
    "devDependencies": {
        "@types/node": "^17.0.24",
        "@types/react": "=18.0.1",
        "@types/react-dom": "^17.0.1",
        "postcss-preset-env": "^7.4.3",
        "tailwindcss": "^3.0.23",
        "typescript": "^4.6.3"
    },
    "version": "1.0.0"
}

My tsconfig.json

{
    "compilerOptions": {
        "target": "esnext",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": false,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve"
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
    "exclude": ["node_modules"]
}

This error was mentioned in #36085, #36103, and #36103. I have attempted to change the Next version to the most recent canary as well as the specified 12.1.5-canary.6. Additionally, I have attempted to downgrade @types/react to version 18.0.1.

Expected Behavior

next build should not result in any errors and should deploy successfully.

To Reproduce

Run yarn create next-app next-tailwind-typescript-starter --example with-typescript and yarn add --dev @types/react @types/react-dom @types/node. Attempt to build (specifically on Vercel in my case) with next build.

@ryandotelliott ryandotelliott added the bug Issue was opened via the bug report template. label Apr 15, 2022
@ryandotelliott
Copy link
Author

By moving all devDependencies into dependencies I've temporarily solved the issue, but this feels like a very incorrect solution.

@ijjk
Copy link
Member

ijjk commented Apr 16, 2022

Hi, can you confirm your lockfile package-lock.json or yarn.lock (note you should only have one or the other) was properly updated between deploys? It sounds like it may have been out of date and after moving your devDependencies to dependencies it got updated.

@ryandotelliott
Copy link
Author

Hi, can you confirm your lockfile package-lock.json or yarn.lock (note you should only have one or the other) was properly updated between deploys? It sounds like it may have been out of date and after moving your devDependencies to dependencies it got updated.

it looks like my Yarn.lock is correct, but I could be wrong. Here's the lock for Next:

next@canary:
  version "12.1.6-canary.2"
  resolved "https://registry.yarnpkg.com/next/-/next-12.1.6-canary.2.tgz#b783c8805cfeda5f1686147c674447a94940ffae"
  integrity sha512-zlW8wu8Hl1xKfYhQId4vvQrPwktaUk6ccnfMrLubnbdX+jF6HbBY/vgFrflW0J+rvwDlBWfyvmZ8N6IRW0zIWQ==
  dependencies:
    "@next/env" "12.1.6-canary.2"
    caniuse-lite "^1.0.30001283"
    postcss "8.4.5"
    styled-jsx "5.0.1"
  optionalDependencies:
    "@next/swc-android-arm-eabi" "12.1.6-canary.2"
    "@next/swc-android-arm64" "12.1.6-canary.2"
    "@next/swc-darwin-arm64" "12.1.6-canary.2"
    "@next/swc-darwin-x64" "12.1.6-canary.2"
    "@next/swc-linux-arm-gnueabihf" "12.1.6-canary.2"
    "@next/swc-linux-arm64-gnu" "12.1.6-canary.2"
    "@next/swc-linux-arm64-musl" "12.1.6-canary.2"
    "@next/swc-linux-x64-gnu" "12.1.6-canary.2"
    "@next/swc-linux-x64-musl" "12.1.6-canary.2"
    "@next/swc-win32-arm64-msvc" "12.1.6-canary.2"
    "@next/swc-win32-ia32-msvc" "12.1.6-canary.2"
    "@next/swc-win32-x64-msvc" "12.1.6-canary.2"
    ```

@talazenkot
Copy link

The same happens to me. The only thing that solved the issue was moving ALL of the dev dependencies to the regular dependencies list.

@ffastym
Copy link

ffastym commented May 19, 2022

The same issue. locally works fine, but on the AWS CodeBuild crashes

UPD: moving ALL of the dev dependencies to the regular dependencies fixed problem, but looks not good :-/
looks like locally uses dependencies installed globally

@ijjk
Copy link
Member

ijjk commented May 22, 2022

Hi, I'm not able to reproduce this following the steps shared, please provide a reproduction with a repo where you are seeing this occur (test deployment can be seen here).

@ijjk ijjk added the please add a complete reproduction Please add a complete reproduction. label May 22, 2022
@y471n
Copy link

y471n commented Jun 22, 2022

I'm also getting the same issue. @DeveloperRyan Were you able to solve this somehow?

@imogenkinsman
Copy link

imogenkinsman commented Jul 7, 2022

Same issue, blocking vercel deploys. Moving everything out of devDependencies reduces the failure down to:

It looks like you're trying to use TypeScript but do not have the required package(s) installed.

Please install @types/react by running:
npm install --save-dev @types/react

Edit: solved with violence. Blew up my package-lock and regenerated it.

@ijjk
Copy link
Member

ijjk commented Jul 8, 2022

@imogenkinsman can you share the repo you saw this occur on before regenerating the package-lock?

@stephank
Copy link

stephank commented Aug 3, 2022

I believe this is fixed. Newer versions of @types/react contain exports in package.json, which means the old Next.js detection broke. It was essentially doing require.resolve("@types/react/index.d.ts"), which stopped working.

The fix is in da6f271 and is part of v12.1.5 and up.

EDIT: Just noticed that that fix should also already be in the versions mentioned by @DeveloperRyan, so this may be unrelated.

@macefti276
Copy link

Seems like there is a bug in some @types/react version. The issue was solved for me by simply updating the @types/react version

In case of npm, do this,
npm install --save-dev @types/react@18.0.1

And for yarn, do
yarn add @types/react@18.0.1

ijjk added a commit that referenced this issue Aug 23, 2022
…39838)

This adds handling for auto-detecting TypeScript being added to a project and installing the necessary dependencies instead of printing the command and requiring the user run the command. We have been testing the auto install handling for a while now with the `next lint` command and it has worked out pretty well. 

This also adds HMR handling for `jsconfig.json`/`tsconfig.json` in development so if the `baseURL` or `paths` configs are modified it doesn't require a dev server restart for the updates to be picked up. 

This also corrects our required dependencies detection as previously an incorrect `paths: []` value was being passed to `require.resolve` causing it to fail in specific situations.

Closes: #36201

### `next build` before

https://user-images.githubusercontent.com/22380829/186039578-75f8c128-a13d-4e07-b5da-13bf186ee011.mp4

### `next build` after


https://user-images.githubusercontent.com/22380829/186039662-57af22a4-da5c-4ede-94ea-96541a032cca.mp4

### `next dev` automatic setup and HMR handling

https://user-images.githubusercontent.com/22380829/186039678-d78469ef-d00b-4ee6-8163-a4706394a7b4.mp4


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants