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

rsocket-websocket-client 1.0.0 browser version compilation with WebPack 5 > example #245

Closed
maxim-bandurko-lsvt opened this issue Sep 6, 2022 · 6 comments
Assignees
Labels
1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release

Comments

@maxim-bandurko-lsvt
Copy link

Hello.

Was trying to compile it for browser using WebPack 5 by adding all needed nodejs polyfills that are used, but failed. Using node-polyfill-webpack-plugin it fails also.

Do you have any setup example how to make it working?

Thank you

@viglucci
Copy link
Member

viglucci commented Sep 6, 2022

Hi @maxim-bandurko-lsvt, specifically which errors are you receiving?

If you are receiving an error about Buffer missing, this article may help. (https://viglucci.io/how-to-polyfill-buffer-with-webpack-5)

@viglucci viglucci self-assigned this Sep 6, 2022
@viglucci viglucci added the 1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release label Sep 6, 2022
@maxim-bandurko-lsvt
Copy link
Author

@viglucci Hello.

Buffer polyfill, yes, it is added. Also, added polyfills to other libraries that are used from nodejs. So, after adding all this, I am getting this error now:

Uncaught (in promise) TypeError: invalid 'instanceof' operand URL
    initAsClient websocket.js:666
    WebSocket websocket.js:85
    wsCreator tmp.js:28
    WebsocketClientTransport WebsocketClientTransport.js:30
    connect WebsocketClientTransport.js:29
    RSocketConnector RSocketConnector.js:88
    step RSocketConnector.js:48
    verb RSocketConnector.js:29
    __awaiter RSocketConnector.js:23
    __awaiter RSocketConnector.js:19
    connect RSocketConnector.js:65

That has just:

if (address instanceof URL) {

At WebPack config I have these plugins:

new NodePolyfillPlugin(),
new webpack.ProvidePlugin({
            process: 'process/browser',
}),
new webpack.ProvidePlugin({
            Buffer: ['buffer', 'Buffer'],
}),

And these resolves:

fallback: { 
            "fs": false,
            "net": false,
            "tls": false,
            "path": false,
            "os": false,
            "zlib": false,
            "crypto": false,
            "https": false,
            "http": false,
            "stream": require.resolve("stream-browserify"),
}

Also, because of global issue had to set:

node: {
        global: true
},

At package.json I have these dependencies added:

    "buffer": "^6.0.3",
    "node-polyfill-webpack-plugin": "^2.0.1",
    "process": "^0.11.10",
    "rsocket-core": "^1.0.0-alpha.3",
    "rsocket-websocket-client": "^1.0.0-alpha.3",
    "stream-browserify": "^3.0.0"

Thank you.

@viglucci
Copy link
Member

viglucci commented Sep 10, 2022

Hey @maxim-bandurko-lsvt not sure you need to add all those additional polyfills, but hard to say without knowing more about the app you are building.

I've put together a minimal working example using only Webpack and rsocket-js, so I don't think there is any issue with using rsocket-js with webpack currently. Please see #246 .

@maxim-bandurko-lsvt
Copy link
Author

@viglucci Thank you for example. It is working. My mistake was that had imported ws to my project:
import WebSocket from "ws"; that pushed WebPack to include all it's dependencies that are not needed.

All is working properly, thank you.

@viglucci
Copy link
Member

Thanks for the update @maxim-bandurko-lsvt , happy to hear you got it working on your end!

@maxim-bandurko-lsvt
Copy link
Author

@viglucci Thanks to you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release
Projects
None yet
Development

No branches or pull requests

2 participants