socketio-shared-webworker icon indicating copy to clipboard operation
socketio-shared-webworker copied to clipboard

Is it possible to use this library with webpack?

Open Krasnov8953 opened this issue 5 years ago • 5 comments

I have an error wile importing lib like this in angular 9 project import * as io from 'socketio-shared-webworker'; or const wio = require('socketio-shared-webworker');

Module parse failed: Unexpected token (9:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| class SharedWorkerSocketIO {
|
>     WorkerType = global.SharedWorker || global.Worker
|     worker = null
|     workerUri = null
i 「wdm」: Failed to compile.

Krasnov8953 avatar May 28 '20 13:05 Krasnov8953

Same problem too! Any idea?

baluhman avatar May 28 '20 13:05 baluhman

hi, this problem is caused by exporting /src/ instead of /dist/ library, which is using ES7 syntax. edit index.js change './src/socket.io-worker' to './dist/socket.io-worker' will solve this problem

require('socketio-shared-webworker') // returns {} idk y
const io = global.wio

arily avatar Oct 24 '20 08:10 arily

Hi there!

I'm afraid I'm not quite understanding how to use this library with ES6 syntax; would anyone happen to have an example using import?

I've tried a few variations of the below, but I can't seem to make anything stick import * as wio from 'socketio-shared-webworker/dist/socket.io-worker';

warrenspe avatar Apr 29 '21 02:04 warrenspe

You can use this with babel but you'll need to enable the babel plugin https://babeljs.io/docs/en/babel-plugin-proposal-class-properties

Here is the .babelrc file used by the project:

{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-proposal-class-properties"]
}

fijiwebdesign avatar Jul 13 '21 14:07 fijiwebdesign

How can I use it in the next.js project... TypeError: socketio_shared_webworker__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function

vickyMeheraj avatar Apr 10 '23 09:04 vickyMeheraj