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

Next.js does not understand TypeScript project references #67372

Open
remcohaszing opened this issue Jul 2, 2024 · 0 comments
Open

Next.js does not understand TypeScript project references #67372

remcohaszing opened this issue Jul 2, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.

Comments

@remcohaszing
Copy link
Contributor

remcohaszing commented Jul 2, 2024

Link to the code that reproduces this issue

https://github.com/remcohaszing/recma-nextjs-static-props/tree/3944549ef8923e91bb3a8ee2542fbc4e67a69e9b

To Reproduce

  1. Clone the project, checkout the broken commit, and install.
    git clone https://github.com/remcohaszing/recma-nextjs-static-props.git
    cd recma-nextjs-static-props
    git checkout 3944549ef8923e91bb3a8ee2542fbc4e67a69e9b
    npm ci
  2. Validate the project with TypeScript.
    npx tsc --build
  3. Great! That works. Now clean up.
    npx tsc --build --clean
  4. Build the project with Next.js.
    npx next build
  5. Observe the type error.
      ▲ Next.js 14.2.4
    
       Linting and checking validity of types  ...Failed to compile.
    
    ./fixtures/custom-name/options.js:2:51
    Type error: Could not find a declaration file for module 'recma-nextjs-static-props'. 
    '/home/remco/Projects/recma-nextjs-static-props/lib/recma-nextjs-static-props.js' implicitly has an 'any' type.
      Try `npm i --save-dev @types/recma-nextjs-static-props` if it exists or add a new declaration (.d.ts) file containing `declare module 'recma-nextjs-static-props';`
    
      1 | /**
    > 2 |  * @import { RecmaNextjsStaticPropsOptions } from 'recma-nextjs-static-props'
        |                                                   ^
      3 |  */
      4 |
      5 | /**
    

Current vs. Expected behavior

If tsc --build works, I expect next build to not throw type errors. The likely culprit is that next build doesn’t understand TypeScript project references.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #202405300957~1718348209~22.04~7817b67 SMP PREEMPT_DYNAMIC Mon J
  Available memory (MB): 31807
  Available CPU cores: 12
Binaries:
  Node: 22.3.0
  npm: 10.8.1
  Yarn: 1.22.22
  pnpm: 9.4.0
Relevant Packages:
  next: 14.2.4 // Latest available version is detected (14.2.4).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

TypeScript

Which stage(s) are affected? (Select all that apply)

next build (local), Vercel (Deployed)

Additional context

As a workaround, users can add the following to next.config.mjs:

export default {
  typescript: {
    ignoreBuildErrors: true
  }
}
@remcohaszing remcohaszing added the bug Issue was opened via the bug report template. label Jul 2, 2024
@github-actions github-actions bot added the TypeScript Related to types with Next.js. label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant