【问题标题】:Next.js with Yarn pnp in a mono repo keep failing when trying to buildNext.js with Yarn pnp in a mono repo keep failing when trying to build
【发布时间】:2022-12-02 03:21:54
【问题描述】:

I am running Next.js 13.0.5 with Yarn 3.2.1 and Lerna 5.6.1.

It seems like the main problem here is the build tool, because when I run the Next.js server itself (yarn dev) everything works perfectly.

What error am I getting?

Type error: Cannot find module 'next/app' or its corresponding type declarations.

which happens here right at the start of the program

import type { AppProps } from 'next/app'
                   ^
function MyApp({ Component, pageProps }: AppProps) {
   return <Component {...pageProps} />
}

After looking around I tried some experimental features like swcFileReading : false but it doesn't seem to have any effect.

【问题讨论】:

  • perhaps your build is not running in topological order, are you sure that each package have the dependencies in each package.json files? For example, I assume next/app has to be built before MyApp since it seems to be a dependency
  • @ghiscoding it doesn't really matter, I was able to replicate this when creating a fresh create-next-app with yarn plugnplay (latest), it's a problem with next I think, I already submitted an issue. for now, until it is supported I moved to nodeLinker: pnpm
  • ah ok I never tried Yarn PNP, since I also prefer pnpm with the workspace: protocol which I also use in Lerna-Lite (a lighter alternative to Lerna) itself, both managers are supported by Lerna/Lerna-Lite. Maybe a side comment, make sure to not use lerna boostrap with recent package managers, that command will be removed in Lerna and was never added to Lerna-Lite since it's no longer needed and can conflicts with the package manager

标签: next.js lerna yarn-v3


【解决方案1】:

try restarting Typescript server. here is how if using vsCode.

type: ctrl + shift + p

choose: > TypeScript: Restart TS server

Hope it works.

【讨论】:

    【解决方案2】:

    try:

    yarn dlx @yarnpkg/sdks vscode

    Then you don't need to fallback to nodeLinker: node-modules as other StackOverflow suggestions to this problem. It resolved for me!

    for more info check the yarn/ts issue: https://github.com/yarnpkg/berry/issues/4872#issuecomment-1284318301

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 2022-12-01
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 2017-02-18
      • 2022-12-18
      • 2022-12-27
      相关资源
      最近更新 更多