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

create-next-app --ts not recognising @types/react #36085

Closed
1 task done
JayAchar opened this issue Apr 12, 2022 · 17 comments
Closed
1 task done

create-next-app --ts not recognising @types/react #36085

JayAchar opened this issue Apr 12, 2022 · 17 comments
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. TypeScript Related to types with Next.js.

Comments

@JayAchar
Copy link

JayAchar commented Apr 12, 2022

Verify canary release

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

Provide environment information

Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 19.6.0: Thu Jan 13 01:26:33 PST 2022; root:xnu-6153.141.51~3/RELEASE_X86_64
Binaries:
Node: 16.13.1
npm: 8.3.0
Yarn: 1.22.15
pnpm: 6.11.0
Relevant packages:
next: 12.1.5-canary.6
react: 18.0.0
react-dom: 18.0.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

After running npx create-next-app@latest --ts test-app then cd test-app && npm run dev, I get the following error:


> test-app@0.1.0 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
It looks like you're trying to use TypeScript but do not have the required package(s) installed.

Please install @types/react by running:

yarn add --dev @types/react

If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).


Running the @types/react installation command doesn't fix the problem.
@types/react version 18.0.2 is listed as a devDependency in the package.json.

Expected Behavior

create-next-app@latest --ts should create a template which works when npm run dev is called.

To Reproduce

npx create-next-app@latest --ts test-app

cd test-app && npm run dev

@JayAchar JayAchar added the bug Issue was opened via the bug report template. label Apr 12, 2022
@valstu

This comment was marked as off-topic.

@mattJurz

This comment was marked as off-topic.

1 similar comment
@mrcrazylee

This comment was marked as off-topic.

@andresmanz
Copy link

Downgrading @types/react to 18.0.1 works for me as a workaround. Might be related to facebook/react#24304?

@valstu
Copy link

valstu commented Apr 12, 2022

Downgrading @types/react to 18.0.1 works for me as a workaround. Might be related to facebook/react#24304?

This seems to work 👍

@JayAchar
Copy link
Author

I've got it working again by downgrading only the @types/react package. Thanks @andresmanz

"@types/react": "18.0.1"

@balazsorban44 balazsorban44 added TypeScript Related to types with Next.js. React 18 create-next-app Related to our CLI tool for quickly starting a new Next.js application. and removed bug Issue was opened via the bug report template. labels Apr 12, 2022
@eps1lon
Copy link
Member

eps1lon commented Apr 12, 2022

We added an export map in 18.0.2: DefinitelyTyped/DefinitelyTyped#59838

Maybe this isn't supported by Next?

@balazsorban44
Copy link
Member

I think we have to update our TS config verifier:

const missingPackages = requiredPackages.filter((p) => {
try {
resolutions.set(p.pkg, require.resolve(p.file, { paths: [baseDir] }))
return false
} catch (_) {
return true
}
})

On @types/react@18.0.2, it throws with:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './index.d.ts' is not defined by "exports" in .../node_modules/@types/react/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.mod._resolveFilename (.../node_modules/.pnpm/next@12.1.4_react-dom@18.0.0+react@18.0.0/node_modules/next/dist/build/webpack/require-hook.js:183:28)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at .../node_modules/.pnpm/next@12.1.4_react-dom@18.0.0+react@18.0.0/node_modules/next/dist/lib/has-necessary-dependencies.js:11:44
    at Array.filter (<anonymous>) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}```

@Brooooooklyn
Copy link
Contributor

Closed in #36082

@ijjk
Copy link
Member

ijjk commented Apr 12, 2022

Hi, the above patch is now available in v12.1.5-canary.7 of Next.js, please update and give it a try!

@Spikeysanju
Copy link

Spikeysanju commented Apr 12, 2022

Any update on this?. I have tried above patch v12.1.5-canary.7 & still it's throwing the same issue.

@ijjk
Copy link
Member

ijjk commented Apr 12, 2022

@Spikeysanju can you confirm the latest canary is installed with cat node_modules/next/package.json? We have two confirmations this is resolved on that version here #36103

@Spikeysanju
Copy link

Hey @ijjk, just saw your message. Sweet! It works like a charm. Thanks for helping me out so quick 🙌.

@async9
Copy link

async9 commented May 6, 2022

Downgrading types to 18.0.1 works, but make sure it's not like this "^18.0.1" - should be "18.0.1" without "^" before.

@balazsorban44
Copy link
Member

@async9 this should not be an issue anymore. Make sure you are at least on v12.1.5-canary.7 (You can use latest now, as this is out on the stable release channel)

@apetta
Copy link

apetta commented Jun 4, 2022

I'm unfortunately still getting this issue with "next": "^12.1.6" with "@types/react": "^18.0.9" and "typescript": "^4.7.2"

EDIT: Tried downgrading @types/react to "18.0.1" but no luck. I also noticed "@types/node" was running ahead of my installed node version (v16.15.0) so I downgraded that to "16.11.38" - not sure if that affects this, but also no luck.

Update: Fixed it. Short story is that I was being stupid. Long story is that I needed to omit the "--only=production" part of "RUN npm ci --only=production" on the Dockerfile I wrote 🤦‍♂️

Sorry for the spam! Leaving this here for others...

@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 Jul 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. TypeScript Related to types with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.