Make sure to handle "next" import gracefully (#11733)

* Make sure to handle "next" import gracefully

* Update test file
This commit is contained in:
JJ Kasper 2020-04-07 14:13:01 -05:00 committed by GitHub
parent 44b7b3c953
commit cad2a75649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -473,10 +473,17 @@ export default async function getBaseWebpackConfig(
)
let webpackConfig: webpack.Configuration = {
externals: !isServer
? undefined
? // make sure importing "next" is handled gracefully for client
// bundles in case a user imported types and it wasn't removed
// TODO: should we warn/error for this instead?
['next']
: !isServerless
? [
(context, request, callback) => {
if (request === 'next') {
return callback(undefined, `commonjs ${request}`)
}
const notExternalModules = [
'next/app',
'next/document',

View file

@ -0,0 +1,14 @@
import Link from 'next/link'
// Leave below import, testing that importing "next"
// doesn't stall the build
// eslint-disable-next-line no-unused-vars
import next from 'next'
export default () => (
<div>
<Link href="/about">
<a>About Page</a>
</Link>
<p className="index-page">Hello World</p>
</div>
)