question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

segfault running custom next server within jest unit test after upgrading nextjs 11 -> 12

See original GitHub issue

Run next info (available from version 12.0.8 and up)

N/A

What version of Next.js are you using?

11.1.3 + 12.0.7

What version of Node.js are you using?

16.13.1

What browser are you using?

N/A

What operating system are you using?

macOS

How are you deploying your application?

N/A

Describe the Bug

Within a custom server application there are some unit tests using the jest framework along with supertest to mimic http requests (See replication repo). This has been working as expected up until trying to upgrade to multiple 12.X nextjs versions including 12.0.0, 12.0.1, and 12.0.7.

When running version 12 with a next.config.js configuration present and a custom server with dev: false, the jest execution exits with a segfault when calling app.prepare().

const app = next({
      dev: false,
});

await app.prepare(); // Goes 💥
zsh: segmentation fault  npm test

It is possible to workaround this issue by importing the nextjs config manually and passing it as the conf option to the custom next application.

example workaround

const app = next({
      dev: false,
      conf: require('./next.config'), // this fixes the seg fault
});

await app.prepare(); // No 💥 this time

await request(app.getRequestHandler())
      .get("/")
      .expect(200);

Expected Behavior

I would expect this not to crash and nextjs to be able to resolve the next.config.js automatically without the conf option

To Reproduce

I have published a public GitHub repo that reproduces the following scenarios along with setup instructions

https://github.com/Kauabunga/nextjs-replicate-segfault-custom-server-v12

  1. [✓] jest unit test with version 11.1.3 without a next.config.js
  2. [✓] jest unit test with version 11.1.3 with a next.config.js
  3. [✓] jest unit test with version 12.0.7 without a next.config.js
  4. [✗] jest unit test with version 12.0.7 with a next.config.js
  5. [✓] jest unit test with version 12.0.7 with a next.config.js with custom server options conf: require('next.config')
  6. [✗] jest unit test with version canary with a next.config.js and segfault-handler

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
khasty720commented, Jan 18, 2022
0reactions
github-actions[bot]commented, Feb 18, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm run Segmentation fault: 11 - node.js - Stack Overflow
Best course of action is updating node.js/npm, deleting node_modules folder and running npm install to install dependencies again.
Read more >
How To Set Up Next.JS With Jest, React Testing Library and ...
In this blog post, we'll explore how to set up a Next.JS project with bulletproof testing libraries, including: Unit Testing with Jest and ......
Read more >
First steps, unit tests with Jest on Next.js - Medium
js project using Jest and React Testing Library. To start we need a project to work with, we can get that easily by...
Read more >
Clustering 4000 Stack Overflow tags with BigQuery k-means
In this post he works with BigQuery – Google's serverless data warehouse – to run k-means clustering over Stack Overflow's published dataset ...
Read more >
jest-expo | Yarn - Package Manager
A Jest preset to painlessly test your Expo / React Native apps. ... Until then, you can find them in changelogs of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found