-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn/revert custom devtool in development mode (#14285)
Warn users and revert their `devtool` when they manually change the `devtool` in development mode. For this addition, I check to ensure the `devtool` is custom (i.e. different than what is set by Next) and has a value (`false` is fine as a custom `devtool`!). As described in [this issue (13963)](#13963), changing the `devtool` in development mode can cause issues with performance. Fixes #13963
- Loading branch information
1 parent
afa9bab
commit 435bf65
Showing
5 changed files
with
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Improper webpack `devtool` used in development mode | ||
|
||
#### Why This Error Occurred | ||
|
||
Next.js chooses the most optimal `devtool` for use with webpack. Changing the `devtool` in development mode will cause severe performance regressions with your application. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Please remove the custom `devtool` override or only apply it to production builds in your `next.config.js`. | ||
|
||
```js | ||
module.exports = { | ||
webpack: (config, options) => { | ||
if (!options.dev) { | ||
config.devtool = options.isServer ? false : 'your-custom-devtool' | ||
} | ||
return config | ||
}, | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
webpack: (config) => { | ||
config.devtool = false | ||
return config | ||
}, | ||
} |
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 @@ | ||
import { useEffect } from 'react' | ||
|
||
export default function Index(props) { | ||
useEffect(() => { | ||
throw new Error('this should render') | ||
}, []) | ||
return <div>Index Page</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,58 @@ | ||
/* eslint-env jest */ | ||
|
||
import { | ||
check, | ||
findPort, | ||
getRedboxSource, | ||
hasRedbox, | ||
killApp, | ||
launchApp, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 30) | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
describe('devtool set in developmemt mode in next config', () => { | ||
it('should warn and revert when a devtool is set in development mode', async () => { | ||
let stderr = '' | ||
|
||
const appPort = await findPort() | ||
const app = await launchApp(appDir, appPort, { | ||
env: { __NEXT_TEST_WITH_DEVTOOL: true }, | ||
onStderr(msg) { | ||
stderr += msg || '' | ||
}, | ||
}) | ||
|
||
const found = await check( | ||
() => stderr, | ||
/Reverting webpack devtool to /, | ||
false | ||
) | ||
|
||
const browser = await webdriver(appPort, '/') | ||
expect(await hasRedbox(browser)).toBe(true) | ||
if (process.platform === 'win32') { | ||
// TODO: add win32 snapshot | ||
} else { | ||
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` | ||
"pages/index.js (5:10) @ eval | ||
3 | export default function Index(props) { | ||
4 | useEffect(() => { | ||
> 5 | throw new Error('this should render') | ||
| ^ | ||
6 | }, []) | ||
7 | return <div>Index Page</div> | ||
8 | }" | ||
`) | ||
} | ||
await browser.close() | ||
|
||
await killApp(app) | ||
expect(found).toBeTruthy() | ||
}) | ||
}) |