Giter VIP home page Giter VIP logo

Comments (3)

SilentBot1 avatar SilentBot1 commented on May 27, 2024

Hi @oviirup,

Getting this error typically means that whatever bundler you are using isn't respecting the browser overrides used to build the browser version of WebTorrent, which seems to be a known issue with next.js.

I would recommend using the pre-built browser version from webtorrent/dist/webtorrent.min.js, rather than trying to bundle it yourself. If you are up for the challenge, it appears you could possibly work around this with a custom webpack config in your next.config.js.

from webtorrent.

oviirup avatar oviirup commented on May 27, 2024

@SilentBot1 thanks for the solution. I kept the webtorrent.min.js in lib folder and imported the script in my project. Here is the code for the page.

'use client';

import React from 'react';
import WebTorrent from '@/lib/webtorrent';

export default function HomePage() {
  const client = React.useRef();

  React.useEffect(() => {
    // ignore in server and run only in client
    if (typeof window === 'undefined') return;

    client.current ??= new WebTorrent(); //! ERROR

  }, []);

  return <main>This is main page</main>;
}

In the development server it gives this error

⨯ ReferenceError: self is not defined
   at 9639 (...\.next\server\chunks\ssr\src_6f687d._.js:4290:56)
   at n (...\.next\server\chunks\ssr\src_6f687d._.js:4343:16)
   ...
GET / 500 in 768ms

Though the torrent file is loaded successfully, but this error breaks the build process.

from webtorrent.

SilentBot1 avatar SilentBot1 commented on May 27, 2024

Hi @oviirup,

The error you're getting is due using the browser version of WebTorrent, while also performing SSR (in Node). You will likely want to dynamically import the library with ssr: false, so it only loads on the client and not the server, docs are available here.

from webtorrent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.