diff --git a/packages/next/next-server/lib/loadable.js b/packages/next/next-server/lib/loadable.js index 3b2381b319dfb..73514019d8321 100644 --- a/packages/next/next-server/lib/loadable.js +++ b/packages/next/next-server/lib/loadable.js @@ -94,7 +94,8 @@ function createLoadableComponent(loadFn, options) { if ( !initialized && typeof window !== 'undefined' && - typeof opts.webpack === 'function' + typeof opts.webpack === 'function' && + typeof require.resolveWeak === 'function' ) { const moduleIds = opts.webpack() READY_INITIALIZERS.push((ids) => { diff --git a/test/unit/fixtures/stub-components/hello.js b/test/unit/fixtures/stub-components/hello.js new file mode 100644 index 0000000000000..898cf5f1240fb --- /dev/null +++ b/test/unit/fixtures/stub-components/hello.js @@ -0,0 +1,5 @@ +import React from 'react' + +export default function Hello() { + return
hello
+} diff --git a/test/unit/next-dynamic.test.js b/test/unit/next-dynamic.test.js new file mode 100644 index 0000000000000..31477e93f00ef --- /dev/null +++ b/test/unit/next-dynamic.test.js @@ -0,0 +1,16 @@ +/** + * @jest-environment jsdom + */ +import React from 'react' +import { act, render } from '@testing-library/react' +import dynamic from 'next/dynamic' + +describe('next/dynamic', () => { + it('test link with unmount', () => { + const App = dynamic(() => import('./fixtures/stub-components/hello')) + act(() => { + const { unmount } = render() + unmount() + }) + }) +})