After updating from 9.1.2 to 9.1.3 in our project some tests began to fail
After some research we've found out that those tests directly or indirectly depends on some module from next/document (like import Document, { Html, Head, Main, NextScript } from 'next/document';)
This is the output of the error when running the test suite
โ Test suite failed to run
Cannot find module 'next-plugin-loader?middleware=document-head-tags-server!' from '_document.js'
However, Jest was able to find:
'dist/pages/_document.d.ts'
'dist/pages/_document.js'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
Clone this repo and run the tests
https://github.com/alexandre-marchina/next-with-jest-loader-bug-repro
It was created based on the with-jest example (using the jest.config.js provided by the example), but adding a test to the custom _document.js that imports from next/document
Those tests should pass, but if we rollback to the 9.1.2 everything works just fine
What would be the correct solution for this case?
Hi, this should be fixed in Next.js v9.1.4-canary.5
Thanks @ijjk !
It has been fixed indeed!
+ [email protected]
npm WARN [email protected] No license field.
removed 1 package, updated 5 packages and audited 887403 packages in 27.684s
found 1 high severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
> [email protected] test /home/runner/work/next-with-jest-loader-bug-repro/next-with-jest-loader-bug-repro
> jest
PASS __tests__/index.test.js
PASS __tests__/document.test.js
Test Suites: 2 passed, 2 total
Tests: 3 passed, 3 total
Snapshots: 1 passed, 1 total
Time: 2.492s
Ran all test suites.
Most helpful comment
Hi, this should be fixed in Next.js
v9.1.4-canary.5