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
fix: #34711 ensure distDir inside project folder #34795
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,7 @@ export default class HotReloader { | |
private buildId: string | ||
private middlewares: any[] | ||
private pagesDir: string | ||
private distDir: string | ||
private webpackHotMiddleware?: WebpackHotMiddleware | ||
private config: NextConfigComplete | ||
private runtime?: 'nodejs' | 'edge' | ||
|
@@ -170,12 +171,14 @@ export default class HotReloader { | |
{ | ||
config, | ||
pagesDir, | ||
distDir, | ||
buildId, | ||
previewProps, | ||
rewrites, | ||
}: { | ||
config: NextConfigComplete | ||
pagesDir: string | ||
distDir: string | ||
buildId: string | ||
previewProps: __ApiPreviewProps | ||
rewrites: CustomRoutes['rewrites'] | ||
|
@@ -185,6 +188,7 @@ export default class HotReloader { | |
this.dir = dir | ||
this.middlewares = [] | ||
this.pagesDir = pagesDir | ||
this.distDir = distDir | ||
this.clientStats = null | ||
this.serverStats = null | ||
this.serverPrevDocumentHash = null | ||
|
@@ -435,15 +439,15 @@ export default class HotReloader { | |
startSpan.stop() // Stop immediately to create an artificial parent span | ||
|
||
await this.clean(startSpan) | ||
|
||
// Ensure distDir exists before writing package.json | ||
await fs.mkdir(this.config.distDir, { recursive: true }) | ||
await fs.mkdir(this.distDir, { recursive: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
|
||
const distPackageJsonPath = join(this.distDir, 'package.json') | ||
|
||
// Ensure commonjs handling is used for files in the distDir (generally .next) | ||
// Files outside of the distDir can be "type": "module" | ||
await fs.writeFile( | ||
join(this.config.distDir, 'package.json'), | ||
'{"type": "commonjs"}' | ||
) | ||
await fs.writeFile(distPackageJsonPath, '{"type": "commonjs"}') | ||
|
||
const configs = await this.getWebpackConfig(startSpan) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,7 @@ export default class DevServer extends Server { | |
|
||
this.hotReloader = new HotReloader(this.dir, { | ||
pagesDir: this.pagesDir!, | ||
distDir: this.distDir, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this.distDir // here distDir is the absolute path |
||
config: this.nextConfig, | ||
previewProps: this.getPreviewProps(), | ||
buildId: this.buildId, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.