Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning when importing "next" directly (#35884)
* Add warning when importing "next" directly * Apply suggestions from code review Co-authored-by: Balázs Orbán <info@balazsorban.com> * Apply suggestions from code review Co-authored-by: Steven <steven@ceriously.com> * add example Co-authored-by: Balázs Orbán <info@balazsorban.com> Co-authored-by: Steven <steven@ceriously.com>
- Loading branch information
1 parent
384953b
commit b1a7b88
Showing
6 changed files
with
44 additions
and
0 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,17 @@ | ||
# Invalid "next" Import | ||
|
||
#### Why This Error Occurred | ||
|
||
Somewhere in your application, you imported `next` directly which is only meant to be used with legacy custom servers. | ||
|
||
You should not import `next` inside of pages or components. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Ensure any usage of `import next from "next"` is specific to custom server usage and isn't included in your pages or components. | ||
|
||
Also ensure any type imports are kept inside of TypeScript files e.g. ensure `import { PageConfig } from 'next'` isn't used in JavaScript files. | ||
|
||
### Useful Links | ||
|
||
- [Custom Server Documentation](https://nextjs.org/docs/advanced-features/custom-server) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as Log from '../build/output/log' | ||
|
||
Log.warn( | ||
`"next" should not be imported directly, imported in ${module.parent?.filename}\nSee more info here: https://nextjs.org/docs/messages/import-next` | ||
) |
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