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

[When using yarn PNP] TypeError: Cannot read properties of undefined (reading 'on') #46993

Closed
1 task done
simPod opened this issue Mar 10, 2023 · 5 comments · Fixed by #47784
Closed
1 task done

[When using yarn PNP] TypeError: Cannot read properties of undefined (reading 'on') #46993

simPod opened this issue Mar 10, 2023 · 5 comments · Fixed by #47784
Labels
bug Issue was opened via the bug report template.

Comments

@simPod
Copy link
Contributor

simPod commented Mar 10, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 19.6.1
      npm: 9.4.0
      Yarn: 4.0.0-rc.40
      pnpm: N/A
    Relevant packages:
      next: 13.2.4
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

To Reproduce

Use yarn pnp and build app.

It was introduces in this PR #46705 I believe

worker._child.on('exit', (code, signal) => {

Describe the Bug

TypeError: Cannot read properties of undefined (reading 'on')
    at createWorker (/src/.yarn/__virtual__/next-virtual-9c7084ba23/4/build-cache/yarn/cache/next-npm-13.2.4-eedd00f0a6-9.zip/node_modules/next/dist/lib/worker.js:32:31)
    at new Worker (/src/.yarn/__virtual__/next-virtual-9c7084ba23/4/build-cache/yarn/cache/next-npm-13.2.4-eedd00f0a6-9.zip/node_modules/next/dist/lib/worker.js:42:9)
    at /src/.yarn/__virtual__/next-virtual-9c7084ba23/4/build-cache/yarn/cache/next-npm-13.2.4-eedd00f0a6-9.zip/node_modules/next/dist/build/index.js:593:35
    at async Span.traceAsyncFn (/src/.yarn/__virtual__/next-virtual-9c7084ba23/4/build-cache/yarn/cache/next-npm-13.2.4-eedd00f0a6-9.zip/node_modules/next/dist/trace/trace.js:79:20)
    at async Object.build [as default] (/src/.yarn/__virtual__/next-virtual-9c7084ba23/4/build-cache/yarn/cache/next-npm-13.2.4-eedd00f0a6-9.zip/node_modules/next/dist/build/index.js:73:2

Expected Behavior

No error. 13.2.1 works

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@simPod simPod added the bug Issue was opened via the bug report template. label Mar 10, 2023
@timmywil
Copy link
Contributor

I get the same error using regular old npm. Just running next build. No error in 13.2.3.

@timmywil
Copy link
Contributor

Ok, after some digging, this can be reproduced with a fresh project created with npx create-next-app@latest, but only with the following in the next.config.js:

experimental: {
  workerThreads: true
}

I forget why I added that. I actually used yarn pnp in the past and switched back to default npm so it's likely an artifact leftover from some solution I found in nextjs issues to fix a yarn pnp issue.

Removing that does seem to fix it, but I don't know if that will be possible for everyone.

@simPod
Copy link
Contributor Author

simPod commented Mar 10, 2023

You're right. I had that enabled too but removing it seems to have no effect. It was somehow required for pnp before but not anymore.

@SukkaW
Copy link
Contributor

SukkaW commented Apr 1, 2023

@simPod I have created a PR #47784 to fix the issue.

@kodiakhq kodiakhq bot closed this as completed in #47784 Apr 1, 2023
kodiakhq bot pushed a commit that referenced this issue Apr 1, 2023
Fixes #46993.

The issue is introduced in #46705 by @ijjk 

Next.js uses `jest-worker` for multiprocessing. `jest-worker` supports both `child_process` and `worker_threads` modes. Next.js use `child_process` mode by default, but can also switch to using `worker_threads` mode with an experimental flag `config.experimental.workerThreads`.

In #46705, @ijjk applies a fix that works for the `child_process` mode, which breaks the `worker_threads` mode (`jest-worker`'s `NodeThreadWorker` interface doesn't have the private property `_child`), causing static HTML export to fail with the following error (#46993):

```
> Build error occurred
TypeError: Cannot read properties of undefined (reading 'on')
    at createWorker (/Users/[redacted]/node_modules/next/dist/lib/worker.js:32:31)
    at new Worker (/Users/[redacted]/node_modules/next/dist/lib/worker.js:42:9)
    at /Users/[redacted]/node_modules/next/dist/build/index.js:629:35
    at async Span.traceAsyncFn (/Users/[redacted]/node_modules/next/dist/trace/trace.js:79:20)
    at async Object.build [as default] (/Users/[redacted]/node_modules/next/dist/build/index.js:74:29)
```

The PR fixes that.
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

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 May 2, 2023
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

Successfully merging a pull request may close this issue.

3 participants