Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kauabunga opened this issue Jan 5, 2022 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@Kauabunga
Copy link

Kauabunga commented Jan 5, 2022

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
@Kauabunga Kauabunga added the bug Issue was opened via the bug report template. label Jan 5, 2022
@peterbe
Copy link

peterbe commented Jan 5, 2022

Me too! I'm trying next 12.0.7 with Node 17 and 16. Your fix solved it. Except, instead of require() I use:

import conf from '../next.config.js'
...
export const nextApp = next({ dev: isDevelopment, conf })

and now, 100% less seg faults.

@ide
Copy link

ide commented Jan 11, 2022

It looks like the error comes from here: https://cs.github.com/v8/v8/blob/17a99fec258bcc07ea9fc5e4fabcce259751db03/src/runtime/runtime-module.cc?q=RunHostImportModuleDynamicallyCallback+DynamicImportCall#L43-L44

I haven't looked very closely at it since this isn't an urgent/significant issue for me but I suspect using d8 will be helpful to inspect program state since the call stack is in an async/await trampoline.

@khasty720
Copy link
Contributor

Same issue reported here #31162

@balazsorban44
Copy link
Member

Duplicate of #31162

@balazsorban44 balazsorban44 marked this as a duplicate of #31162 Jan 19, 2022
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

5 participants