Next.js Discord

Discord Forum

setting distDir to outside project directory

Answered
charcoal posted this in #help-forum
Open in Discord
im working in a monorepo where all apps are built to a centralised dist folder at the root of the project. my nextjs app is in apps/site and i've set the distDir config to the dist/site directory, but it's causing errors while building. i checked the docs and they're saying that setting distDir to outside the project directory is invalid. is there a workaround for this?
Answered by @ts-ignore
you can write a script which moves the content to your desired dir once build is completed
View full answer

5 Replies

this is the error i'm getting for added context:
apps/site postinstall$ next build
│    Creating an optimized production build ...
│  ✓ Compiled successfully
│    Linting and checking validity of types ...
│ Failed to compile.
│ ../../dist/site/types/app/account/page.ts:3:40
│ Type error: Cannot find module 'next/dist/lib/metadata/types/metadata-interface.js' or its corresponding type declarations.
│   1 | // File: C:\Users\Charlie\OneDrive\Documents\coding\phase\apps\site\app\account\page.tsx
│   2 | import * as entry from '../../../../../apps/site/app/account/page.js'
│ > 3 | import type { ResolvingMetadata } from 'next/dist/lib/metadata/types/metadata-interface.js'
│     |                                        ^
│   4 | 
│   5 | type TEntry = typeof import('../../../../../apps/site/app/account/page.js')
│   6 | 
└─ Failed in 19.4s at C:\Users\Charlie\OneDrive\Documents\coding\phase\apps\site
and for next.config.js, this is the distDir i've set: distDir: '../../dist/site'
and for more context my file structure looks something like this:
monorepo/
  apps/
    site/
      next.config.js
      app/
      ...
  other-apps/
    ...
  dist/
  ...
@charcoal and for more context my file structure looks something like this: monorepo/ apps/ site/ next.config.js app/ ... other-apps/ ... dist/ ...
you can write a script which moves the content to your desired dir once build is completed
Answer