ThaUnknown / webrtc-polyfill

3 stars 0 forks source link

Module not found when using with next.js #4

Closed snimshchikov closed 2 months ago

snimshchikov commented 2 months ago

A very cool project https://github.com/dmotz/trystero now uses your library fork simple-peer

But when using with next.js it gives an obscure error "Module not found: Default condition should be last one" (https://github.com/dmotz/trystero/issues/76)

I see, that before version 1.1.1 the order of exports was wrong, but it was fixed here https://github.com/ThaUnknown/webrtc-polyfill/commit/8b9e26db4358c8c61ee1619b076af9611a670665. Trystero uses simle-peer ^10.0.7, which uses webrtc-polyfill ^1.1.6, but I still get the error 🤯

My capacity to understand this building nightmare is over, maybe you can magically fix something so it would work?

Thanks in advance

ThaUnknown commented 2 months ago

they simply need to bump versions? this should be an issue on their repo, not here

snimshchikov commented 1 month ago

The issue persists in the latest version of webrtc-polyfill

Steps to reproduce:

  1. Create next.js project using create-t3-app
    npm create t3-app@latest
  2. I used following settings:
    o  What will your project be called?
    |  test-polyfill
    |
    o  Will you be using TypeScript or JavaScript?
    |  TypeScript
    |
    o  Will you be using Tailwind CSS for styling?
    |  No
    |
    o  Would you like to use tRPC?
    |  No
    |
    o  What authentication provider would you like to use?
    |  None
    |
    o  What database ORM would you like to use?
    |  None
    |
    o  Would you like to use Next.js App Router?
    |  Yes
    |
    o  Should we initialize a Git repository and stage the changes?
    |  No
    |
    o  Should we run 'npm install' for you?
    |  Yes
    |
    o  What import alias would you like to use?
    |  ~/
  3. Install latest version of webrtc-polyfill
    npm install webrtc-polyfill
  4. Add import to ~/src/app/page.tsx (and use it)
    import { RTCPeerConnection } from 'webrtc-polyfill'
    if (3*3 === 4) new RTCPeerConnection()
  5. Run server
    npm run dev
  6. Open http://localhost:3000/ and get error
    
    Module not found: Default condition should be last one

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module: ./node_modules/webrtc-polyfill/index.js

./src/app/page.tsx



Note: I couldn't reproduce the issue with default nextjs starter app (everything worked fine)
ThaUnknown commented 1 month ago

t3-app is not npm install webrtc-polyfill, default is latest, as per https://github.com/ThaUnknown/webrtc-polyfill/commit/8b9e26db4358c8c61ee1619b076af9611a670665, t3-app needs to update their dependencies