Next.js: 9.1.3 fails using Jest when a test involves something imported from next/document

Created on 13 Nov 2019  ยท  2Comments  ยท  Source: vercel/next.js

Bug report

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)

To Reproduce

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

Expected behavior

Those tests should pass, but if we rollback to the 9.1.2 everything works just fine

System information

  • OS: [Linux Ubuntu 18.04.3]
  • Version of Next.js: [9.1.3]

What would be the correct solution for this case?

bug

Most helpful comment

Hi, this should be fixed in Next.js v9.1.4-canary.5

All 2 comments

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.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sospedra picture sospedra  ยท  3Comments

olifante picture olifante  ยท  3Comments

renatorib picture renatorib  ยท  3Comments

irrigator picture irrigator  ยท  3Comments

rauchg picture rauchg  ยท  3Comments