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)
- Clone the repo https://github.com/PrudviGali/nextjs-dynamic-import-test-fail
- npm install
- 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
- Fix dynamic import in non webpack env regression #3345 — committed to vladnicula/next.js by deleted user 9 years ago
- Fix dynamic import in non webpack env regression #3345 (#4208) Just in case #3345 was a regression and nextjs should still support non webpack node envs for testing. — committed to vercel/next.js by vladnicula 8 years ago
- Fix dynamic import in non webpack env regression #3345 (#4208) Just in case #3345 was a regression and nextjs should still support non webpack node envs for testing. — committed to lependu/next.js by vladnicula 8 years ago
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 functionerror.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-importexample with jest/enzyme test suites and it is working as expected in the browser. Only problem is with jest testing ofdynamic(....).