https://github.com/danoc/next.js-async-listener-reproduction
https://github.com/danoc/next.js-async-listener-reproduction
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/danoc/next.js-async-listener-reproduction
- Owner: danoc
- Created: 2021-08-05T15:52:09.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T01:16:49.000Z (over 3 years ago)
- Last Synced: 2026-02-06T03:22:42.835Z (5 months ago)
- Language: JavaScript
- Size: 157 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# next.js-async-listener-reproduction
This is a minimal reproduction of an issue with Next.js, custom servers, Webpack 5, and `async-listener`. The corresponding issue is: https://github.com/vercel/next.js/issues/27792
## Issue
[Importing `aysnc-listener` in a custom Next.js server](https://github.com/danoc/next.js-async-listener-reproduction/blob/fe0ec92bdc64b1449257ff7c3410aa3327eeceec/server.js#L2) on a project that uses Webpack 5 will throw the following error:
```
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
(node:6406) UnhandledPromiseRejectionWarning: Error: Unexpected lazy element in stream
at readU8 (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:121549:11)
at BinaryMiddleware._deserialize (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:121842:20)
at BinaryMiddleware.deserialize (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:121454:15)
at Serializer.deserialize (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:123401:26)
at PackFileCacheStrategy._openPack (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:77661:5)
at new PackFileCacheStrategy (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:77633:27)
at WebpackOptionsApply.process (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:73976:9)
at createCompiler (~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:141356:28)
at ~/next-repro/node_modules/next/dist/compiled/webpack/bundle5.js:141319:48
at Array.map ()
(node:6406) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6406) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:6406) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '~/next-repro/.next/cache/webpack/client-development/index.pack'
(node:6406) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
```
I stumbled upon this when trying to integrate Next.js into a codebase that uses `zipkin-context-cls`. `zipkin-context-cls` depends on `continuation-local-storage` which itself depends on `async-listener`.
This fails with both Node 12 and 14.
## Reproduction
Clone this codebase then:
```bash
yarn install
node server.js
```
Notice that commenting out [the problematic line](https://github.com/danoc/next.js-async-listener-reproduction/blob/aa9adc171aa03c38acede2a2f69a73e9f5204ce5/server.js#L2) or [using Webpack 4](https://github.com/danoc/next.js-async-listener-reproduction/blob/1e318279dbf25a61822e1195a0728571ae7bf72b/next.config.js#L3) makes the error go away. Also, this error only appears when `next({ dev: true })`. The issue does not appear in production builds.