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

NextJS - Cannot read properties of undefined (reading 'listen') #1574

Closed
4 tasks done
kevinstark86 opened this issue Mar 22, 2023 · 2 comments
Closed
4 tasks done

NextJS - Cannot read properties of undefined (reading 'listen') #1574

kevinstark86 opened this issue Mar 22, 2023 · 2 comments
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@kevinstark86
Copy link

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 14 or higher

Node.js version

v18.13.0

Reproduction repository

https://github.com/kevinstark86/smiley

Reproduction steps

npm install
npm run dev

Current behavior

Unable to call the correct msw setup using server.listen() or worker.start()

Screenshot 2023-03-22 at 20 55 01

Throws an error saying "TypeError: Cannot read properties of undefined (reading 'listen')

Screenshot 2023-03-22 at 20 55 40

I have followed issue #1227 which suggests that something is forcing the modules to be important asynchronously. The solution given in issue #1227 was to async await import server and worker. However, this has not resolved the problem.

Expected behavior

I expect the correct MSW setup to be called.

@kevinstark86 kevinstark86 added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Mar 22, 2023
@kettanaito
Copy link
Member

Hi, @kevinstark86. Thanks for reporting this.

It looks like there's no exported property server from the ./server module. Can you show me what's the content of that module?

It also seems that the Next.js team recommends using import since require statements won't be tree-shaken and MSW will, inevitably, end up in your production bundle even if you enable it conditionally. Please try switching to await import('./server'), that has to help.

If it doesn't, inspect the exported object from those modules and see what may be wrong:

const obj = await import('./server')
console.log(obj) // what keys are here? 

@kettanaito
Copy link
Member

Also, if encountering issues with Next 13, please follow #1644 where we track the progress of supporting the App directory. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

2 participants