next.js: Dynamic imports testing failure

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Next.js dynamic imports should work with jest test suites.

Current Behavior

It is failing when we run the test with the following error. TypeError: require.resolveWeak is not a function

Steps to Reproduce (for bugs)

  1. Clone the repo https://github.com/PrudviGali/nextjs-dynamic-import-test-fail
  2. npm install
  3. npm run test

Your Environment

Tech Version
next 4.1.3
node 6.9.1
OS mac OS high sierra
browser NA
etc NA

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 6
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Hey, sorry for the necro post, but I’m using Next 5.0.0 and it looks like this issue is still happening. I’m trying to run a jest snapshot test over a page with a dynamically loaded component and running into the TypeError: require.resolveWeak is not a function error.

I followed the thread and found that the fix mentioned above was removed as part of the new universal webpack change, which could have affected the fix. Is this still supposed to work?

https://github.com/zeit/next.js/commit/e093441bad588e98765a05df90f76f75283eda07#diff-f6a1a602536347313a67de6bccddafd4L19

https://github.com/PrudviGali/nextjs-dynamic-import-test-fail repo is a clone of with-dynamic-import example with jest/enzyme test suites and it is working as expected in the browser. Only problem is with jest testing of dynamic(....).