-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add experimental flag to allow forcing NODE_ENV=development in builds (…
…#65463) For debugging purposes, it can be useful to set `NODE_ENV=development` during a `next build`. Currently this value is forced to be production in Next.js. This PR adds an experimental flag to not force a mode of `production` when the flag is set. To use this flag, you'll still need to explicitly set `NODE_ENV=development`, while also enabling `nextConfig.experimental.allowDevelopmentBuild` Closes NEXT-3277
- Loading branch information
Showing
9 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
test/production/allow-development-build/allow-development-build.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('allow-development-build', () => { | ||
describe('with NODE_ENV set to development', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
env: { | ||
NODE_ENV: 'development', | ||
}, | ||
nextConfig: { | ||
experimental: { | ||
allowDevelopmentBuild: true, | ||
}, | ||
}, | ||
}) | ||
|
||
it('should warn about a non-standard NODE_ENV', () => { | ||
expect(next.cliOutput).toContain( | ||
'You are using a non-standard "NODE_ENV" value in your environment' | ||
) | ||
}) | ||
|
||
it.each(['app-page', 'pages-page'])( | ||
`should show React development errors in %s`, | ||
async (page) => { | ||
const browser = await next.browser(page, { | ||
pushErrorAsConsoleLog: true, | ||
}) | ||
|
||
await retry(async () => { | ||
const logs = await browser.log() | ||
|
||
const errorLogs = logs.filter((log) => log.source === 'error') | ||
|
||
expect(errorLogs).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
message: expect.toBeOneOf([ | ||
expect.stringContaining( | ||
"Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client." | ||
), | ||
expect.stringContaining( | ||
'There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.' | ||
), | ||
]), | ||
source: 'error', | ||
}, | ||
]) | ||
) | ||
}) | ||
} | ||
) | ||
}) | ||
|
||
describe('with NODE_ENV not set to development', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
skipStart: true, | ||
nextConfig: { | ||
experimental: { | ||
allowDevelopmentBuild: true, | ||
}, | ||
}, | ||
}) | ||
|
||
it('should fail the build with a message about not setting NODE_ENV', async () => { | ||
await next.start().catch(() => {}) | ||
expect(next.cliOutput).toContain( | ||
"The experimental.allowDevelopmentBuild option requires NODE_ENV to be explicitly set to 'development'" | ||
) | ||
}) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
test/production/allow-development-build/app/app-page/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use client' | ||
import React from 'react' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
Hello World{' '} | ||
{typeof window !== 'undefined' && <span>Hydration Error!</span>} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function Page() { | ||
return ( | ||
<div> | ||
Hello World{' '} | ||
{typeof window !== 'undefined' && <span>Hydration Error!</span>} | ||
</div> | ||
) | ||
} |