Coder Social home page Coder Social logo

Can't construct WebSocket about isomorphic-ws HOT 5 CLOSED

heineiuo avatar heineiuo commented on September 23, 2024
Can't construct WebSocket

from isomorphic-ws.

Comments (5)

julien-f avatar julien-f commented on September 23, 2024

How do you bundle your code?

from isomorphic-ws.

kirillt avatar kirillt commented on September 23, 2024

@julien-f with Babel and WebPack
Here is my package.json:

{
  "private": true,
  "scripts": {
    "build": "babel src -d lib; webpack",
    "start": "budo dist/index.js:index.js --ssl --cert ...  --key ..."
  },
  "dependencies": {
    "isomorphic-ws": "^4.0.1",
    "ws": "^7.2.5"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.6",
    "@babel/preset-env": "^7.9.6",
    "budo": "^11.6.3",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11"
  },
  "browserslist": "> 0.25%, not dead"
}

from isomorphic-ws.

julien-f avatar julien-f commented on September 23, 2024

I suspect that your code is using the Node implementation provided by node.js instead of the browser implementation provided by browser.js.

Make sure that your bundler supports the browser entry in package.json:

"browser": "browser.js",

from isomorphic-ws.

kirillt avatar kirillt commented on September 23, 2024

Thank you @julien-f but this doesn't work for me. I tried to call src/index.js directly bypassing bundlers, but the result is the same. Is there a minimal example working in browser which uses this library? I agree, the issue is quite weird since I don't see any dependencies to satisfy except ws.

from isomorphic-ws.

julien-f avatar julien-f commented on September 23, 2024

In browser, the module should use the code in browser.js, you can try by directly requiring/importing 'isomorphic-ws/browser.js'.

This module is automatically selected if the bundler supports the browser entry in package.json.

from isomorphic-ws.

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.