Socket.io-client: Webpack build issues with 1.4.1

Created on 7 Jan 2016  ·  57Comments  ·  Source: socketio/socket.io-client

With 1.4.1 I am seeing the following issue from Webpack. My code has no issues with 1.4.0

WARNING in ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in /u//WebStormProjects/myProject/node_modules/mySubApp/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/lib
 @ ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/BufferUtil.js 10:19-40

WARNING in ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in /u//WebStormProjects/myProject/node_modules/mySubApp/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/lib
 @ ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/Validation.js 10:19-44

ERROR in ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js
Module not found: Error: Cannot resolve module 'tls' in /u//WebStormProjects/myProject/node_modules/mySubApp/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/lib
 @ ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js 15:10-24

ERROR in ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js
Module not found: Error: Cannot resolve module 'fs' in /u//WebStormProjects/myProject/node_modules/mySubApp/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/node_modules/options/lib
 @ ./~/mySubApp/~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js 6:9-22

Most helpful comment

Warnings disappeared when I included

import * as io from "socket.io-client";

instead of

import * as io from "socket.io";

Still, I have behavior as in #1088. Minimal app with bug is in that issue thread.

_Edit: Solved my issue. It wasn't because of socket.io._

All 57 comments

+1

I recommend for now:

  module: {
    noParse: ['ws']
  },
  externals: ['ws']

until we figure out a better fix

Reason is probably that the published package on npm contains a webpack.config.js file which it didn't with <=1.4.0. Where is that coming from anyway? I can't see it in the repo.

Browserify build fails too. Forcing usage of 1.4.0 fixes the issue.

I accidentally published that file. I was experimenting with moving away from browserify.

1.4.3 out.

Note to self: should explicitly set files in package.json

Still having the same issues with 1.4.3. Adding:

 module: {
    noParse: ['ws']
  },
  externals: ['ws']

Helps though.

Still broken.

@Levino I think you'll have to make browserify ignore/exclude ws, like there

But any solution better than this workaround will be warmly welcomed.

I just use version "~1.3.7" instead of "^1.3.7" in my packages for now.

Moved this from server to this socket.io-client thread.


Was running 1.3.7 and used npm to update socket.io-client to 1.4.3.

The app uses just the socket.io-client to connect to a game server(also updated to socket.io 1.4.3). Developing on windows 7.

Tried uninstalling via npm and reinstalling. Did not expect to see warnings and errors from socket.io-client and engine.io-client when starting the app.

Shouldn't the missing modules be part of the npm package?

Warnings:

WARNING in ./~/socket.io-client/~/engine.io-client/~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in C:\Data\captchatheprize.com\dev\gamewww\node_modules\socket.io-client\node_modules\engine.io-clie
nt\node_modules\ws\lib
@ ./~/socket.io-client/~/engine.io-client/~/ws/lib/BufferUtil.js 10:19-40

WARNING in ./~/socket.io-client/~/engine.io-client/~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in C:\Data\captchatheprize.com\dev\gamewww\node_modules\socket.io-client\node_modules\engine.io-
client\node_modules\ws\lib
@ ./~/socket.io-client/~/engine.io-client/~/ws/lib/Validation.js 10:19-44

Errors:

ERROR in ./~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js
Module not found: Error: Cannot resolve module 'tls' in C:\Data\captchatheprize.com\dev\gamewww\node_modules\socket.io-client\node_modules\engine.io-client\node
_modules\ws\lib
@ ./~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js 15:10-24

ERROR in ./~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js
Module not found: Error: Cannot resolve module 'fs' in C:\Data\captchatheprize.com\dev\gamewww\node_modules\socket.io-client\node_modules\engine.io-client\node_
modules\ws\node_modules\options\lib
@ ./~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js 6:9-22

@ADumaine Did you have any issues with 1.3.7? If not just keep using it until this here is solved.

@Levino No 1.3.7 was not having any issues. 1.4.3 actually works. It connects to the server and passes data, but I am still developing locally and not using things like tls. I'll leave it at 1.4.3 for now and test any updates or revert if there are none and we are ready to stage.

We're publishing a more permanent fix today!

Great.

1.4.4 Fixes this for me. Thanks!

1.4.4 fixed it for me too!. Used npm with @latest. Restarted server and there were no warnings or errors.
Thanks!

still an issue for me, i've updated to a latest socket.io-client, ws and webpack, and get the following

WARNING in ./~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in /home/test/Projects/B_Components/node_modules/ws/lib
 @ ./~/ws/lib/BufferUtil.js 10:19-40

WARNING in ./~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in /home/test/Projects/B_Components/node_modules/ws/lib
 @ ./~/ws/lib/Validation.js 10:19-44

WARNING in ./~/mymodule-services/~/sails.io.js/~/request/lib/optional.js
Critical dependencies:
3:11-26 the request of a dependency is an expression
 @ ./~/mymodule-services/~/sails.io.js/~/request/lib/optional.js 3:11-26
webpack: bundle is now VALID.

@mrvini what are the steps to reproduce please? I have the following with socket.[email protected]:

damien@home:~/git/socket.io-client$ webpack . bundle.js
Hash: 321bb2158ab30d957364
Version: webpack 1.12.11
Time: 685ms
    Asset    Size  Chunks             Chunk Names
bundle.js  195 kB       0  [emitted]  main
   [0] ./lib/index.js 1.66 kB {0} [built]
   [1] ./lib/url.js 1.61 kB {0} [built]
  [14] ./lib/manager.js 12 kB {0} [built]
  [43] ./lib/socket.js 7.54 kB {0} [built]
  [46] ./lib/on.js 370 bytes {0} [built]
    + 46 hidden modules

@globexdesigns @ADumaine :heart:

@darrachequesne, I have the following setup
node: v4.2.3

I have my local module that using sails.io.js and socket.io-client libraries
sails.io.js: 0.12.2
socket.io-client: 1.4.4
I am including this module into the application and running webpack server
webpack: 1.12.11
webpack-dev-server: 1.14.1

when I run webpack .bundle.js, everything looks good, however when I try run it as webpack dev server, it throws the error I mentioned above

@mrvini I'm sorry, it seems I am unable to reproduce:

damien@home:~/test$ npm install [email protected]
[email protected] node_modules/socket.io-client
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
damien@home:~/test$ webpack-dev-server --port 9000
Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.12.11
Time: 19ms
webpack: bundle is now VALID.
http://localhost:9000/webpack-dev-server/
webpack result is served from /
content is served from /home/damien/test

image

Am I missing something here?

Thanks @darrachequesne for looking into it, you right, sails.io.js depends on the socket.io-client, but only as a dev dependencies I believe (mostly it depends on request that produces the main issue for some reason).

Critical dependencies:
3:11-26 the request of a dependency is an expression
 @ ./~/mymodule-services/~/sails.io.js/~/request/lib/optional.js 3:11-26

FYI, strange thing is that with WS version 0.8.1, it seems to work

works for again as well, thanks!

Same here...missing many dependencies...

ERROR in ./~/sails.io.js/~/request/request.js
Module not foun @ ./~/sails.io.js/~/request/request.js 30:10-24

ERROR in ./~/sails.io.js/~/request/~/forever-agent/index.js
Module not found
 @ ./~/sails.io.js/~/request/~/forever-agent/index.js 6:10-24

ERROR in ./~/sails.io.js/~/request/~/forever-agent/index.js
Module not found: Error
 @ ./~/sails.io.js/~/request/~/forever-agent/index.js 7:10-24

ERROR in ./~/sails.io.js/~/request/~/mime/mime.js
Module not found
 @ ./~/sails.io.js/~/request/~/mime/mime.js 2:9-22

ERROR in ./~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js
Module not found
 @ ./~/socket.io-client/~/engine.io-client/~/ws/lib/WebSocketServer.js 15:10-24

ERROR in ./~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js
Module not found
 @ ./~/socket.io-client/~/engine.io-client/~/ws/~/options/lib/options.js 6:9-22

I am still seeing this:

[0] WARNING in ./~/sails.io.js/~/request/lib/optional.js
[0] Critical dependencies:
[0] 3:11-26 the request of a dependency is an expression
[0]  @ ./~/sails.io.js/~/request/lib/optional.js 3:11-26

Packages:

    "sails.io.js": "^0.13.3",
    "socket.io": "^1.4.4",
    "socket.io-client": "^1.4.4",

I have tried this webpack config as well:

 module: {
    noParse: ['ws']
  },
  externals: ['ws']

+1

+1

+1

The:

module: {
  ....
    noParse: ['ws']
  },
  externals: ['ws']

doesn't seems to fix it. Now ws module is undefined.

webpack version : 1.13.0
socket.io-client version : 1.4.4

I also have problems since version 1.4.x
My sample project is a simple TODO app with the following versions:

  • NodeJS v5.8.0,
  • NPM v3.7.3,
  • RethinkDB v2.3.2,
  • RethinkDbDash v2.2.18,
  • Aurelia latest Beta,
  • Socket.io v1.4.6,
  • Socket.io-client v1.4.6,
  • ws v1.1.0

Webpack config

  module: {
    noParse: ['ws']
  },
  node: {
    tls: "empty"
  },
  externals: ['fs','ws']

It helps in removing some of the errors and warnings but I still get the following warning and errors.

WARNING in ./~/socket.io-client/socket.io.js
Critical dependencies:
1:475-482 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/socket.io-client/socket.io.js 1:475-482

ERROR in ./~/socket.io-client/package.json
Module parse failed: C:\test\client\node_modules\socket.io-client\package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
    at Parser.pp.raise (C:\test\client\node_modules\acorn\dist\acorn.js:920:13)
    at Parser.pp.unexpected (C:\test\client\node_modules\acorn\dist\acorn.js:1483:8)
    at Parser.pp.semicolon (C:\test\client\node_modules\acorn\dist\acorn.js:1462:73)
    at Parser.pp.parseExpressionStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1976:8)
    at Parser.pp.parseStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1754:188)
    at Parser.pp.parseBlock (C:\test\client\node_modules\acorn\dist\acorn.js:1991:21)
    at Parser.pp.parseStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1735:19)
    at Parser.pp.parseTopLevel (C:\test\client\node_modules\acorn\dist\acorn.js:1648:21)
    at Parser.parse (C:\test\client\node_modules\acorn\dist\acorn.js:1616:17)
    at Object.parse (C:\test\client\node_modules\acorn\dist\acorn.js:882:44)
 @ ./~/socket.io/lib/index.js 10:20-55

ERROR in ./~/accepts/~/mime-db/db.json
Module parse failed: C:\test\client\node_modules\accepts\node_modules\mime-db\db.json Unexpected token (2:40)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:40)
    at Parser.pp.raise (C:\test\client\node_modules\acorn\dist\acorn.js:920:13)
    at Parser.pp.unexpected (C:\test\client\node_modules\acorn\dist\acorn.js:1483:8)
    at Parser.pp.semicolon (C:\test\client\node_modules\acorn\dist\acorn.js:1462:73)
    at Parser.pp.parseExpressionStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1976:8)
    at Parser.pp.parseStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1754:188)
    at Parser.pp.parseBlock (C:\test\client\node_modules\acorn\dist\acorn.js:1991:21)
    at Parser.pp.parseStatement (C:\test\client\node_modules\acorn\dist\acorn.js:1735:19)
    at Parser.pp.parseTopLevel (C:\test\client\node_modules\acorn\dist\acorn.js:1648:21)
    at Parser.parse (C:\test\client\node_modules\acorn\dist\acorn.js:1616:17)
    at Object.parse (C:\test\client\node_modules\acorn\dist\acorn.js:882:44)
 @ ./~/accepts/~/mime-db/index.js 11:17-37

But even with the errors showing, the project and socket still works as intended with multiple browsers.

Also added a Github TODO Sample if anyone wants to reproduce the errors.

I'm experiencing the same issue with 1.4.6. and receiving the same errors as @ghiscoding. I have added the noParse, and externals as described above in the thread. I have a very simple app that may be helpful for debugging.

The only dependencies of the published application are:

"socket.io": "^1.4.6",
"socket.io-client": "^1.4.6"

To reproduce the errors download the repo, run npm install then run npm prepublish

@dbslone thank you. We should also have a test in CI that builds the project with webpack to avoid issues in the future as well.

Same warnings on Socket.IO 1.4.6, webpack 1.13.0.

WARNING in ./~/socket.io-client/socket.io.js
Critical dependencies:
1:475-482 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/socket.io-client/socket.io.js 1:475-482

WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
 @ ./~/express/lib/view.js 78:29-56

WARNING in ./~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in /home/rbozan/Git/mooiboymmo/server/node_modules/ws/lib
 @ ./~/ws/lib/BufferUtil.js 10:19-40

WARNING in ./~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in /home/rbozan/Git/mooiboymmo/server/node_modules/ws/lib
 @ ./~/ws/lib/Validation.js 10:19-44
var webpack = require("webpack");

module.exports = {
    output: {
        filename: "server.min.js"
    },

    target: "node",

    module: {
        loaders: [
            { test: /\.json$/, loader: "json-loader" }
        ]
    }
};

Is there currently a workaround for this? I've tried adding noParse and externals but I still see the errors right above. Using socket.io 1.4.6, webpack 1.13.1

import io from 'socket.io-client/socket.io' seems to work for me (as opposed to import io from 'socket.io')

I still get

WARNING in ./~/socket.io-client/socket.io.js
Critical dependencies:
1:475-482 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.

but... at least it works

@WestleyArgentum I was actually struggling with this too, but then I read the how to use section in the read me. as long as you are you using the socket.io on your server you should be good to go

A standalone build of socket.io-client is exposed automatically by the socket.io server as /socket.io/socket.io.js.

I added <script type="text/javascript" charset="utf-8" src="/socket.io/socket.io.js"></script> to the head of my html and doc and it exposed io as a global, so no need to import.

Socket.IO: 1.4.6
Webpack: 1.13.0
Webpack has 'node' as target in config.

WARNING in ./~/socket.io-client/socket.io.js
Critical dependencies:
1:475-482 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/socket.io-client/socket.io.js 1:475-482

WARNING in ./~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in C:\maestro\frontend\node_modules\ws\lib
 @ ./~/ws/lib/BufferUtil.js 10:19-40

WARNING in ./~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in C:\maestro\frontend\node_modules\ws\lib
 @ ./~/ws/lib/Validation.js 10:19-44

Exactly the same issue as @omerts here... Did anyone come up with a fix?

This seems vaguely related to request/request/issues/1529

Also getting this with both the websocket and ws packages.

Same, getting this error using ws

Socket.IO: 1.7.3
Webpack: 2.2.1
Module not found: Error: Can't resolve 'socket.io-client/package'

@zweifisch, include json loader in your config to solve your problem.

Still I have "WARNING in ./~/engine.io/lib/server.js Critical dependency: the request of a dependency is an expression" and other similar to ones from people above.

I use Angular2. Maybe config will help:

const path = require('path');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const postcssUrl = require('postcss-url');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin, WatchIgnorePlugin } = require('webpack');
const { BaseHrefWebpackPlugin } = require('@angular/cli/plugins/webpack');
const { CommonsChunkPlugin } = require('webpack').optimize;
const { AotPlugin } = require('@ngtools/webpack');

const nodeModules = path.join(process.cwd(), 'node_modules');
const entryPoints = ["inline","polyfills","sw-register","styles","vendor","main"];
const baseHref = undefined;
const deployUrl = undefined;

module.exports = {
  "devtool": "source-map",
  "resolve": {
    "extensions": [
      ".ts",
      ".js",
      ".json"
    ],
    "modules": [
      "./node_modules"
    ],
    "alias": {
      "config": "config/config.dev.js"
    }
  },
  "resolveLoader": {
    "modules": [
      "./node_modules"
    ]
  },
  "entry": {
    "main": [
      "./app/main.ts"
    ],
    "polyfills": [
      "./app/polyfills.ts"
    ],
    "styles": [
      "./dist/style.dev.css"
    ]
  },
  "output": {
    "path": path.join(process.cwd(), "dist/dev"),
    "filename": "[name].bundle.js",
    "sourceMapFilename": "[name].bundle.js.map",
    "chunkFilename": "[id].chunk.js"
  },
  "module": {
    "rules": [
      {
        "enforce": "pre",
        "test": /\.js$/,
        "loader": "source-map-loader",
        "exclude": [
          /\/node_modules\//
        ]
      },
      {
        "test": /\.json$/,
        "loader": "json-loader"
      },
      {
        "test": /\.html$/,
        "loader": "raw-loader"
      },
      {
        "test": /\.(eot|svg)$/,
        "loader": "file-loader?name=[name].[hash:20].[ext]"
      },
      {
        "test": /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/,
        "loader": "url-loader?name=[name].[hash:20].[ext]&limit=10000"
      },
      {
        "exclude": [
          path.join(process.cwd(), "dist/style.dev.css")
        ],
        "test": /\.css$/,
        "loaders": [
          "exports-loader?module.exports.toString()",
          "css-loader?{\"sourceMap\":true,\"importLoaders\":1}",
          "postcss-loader"
        ]
      },
      {
        "exclude": [
          path.join(process.cwd(), "dist/style.dev.css")
        ],
        "test": /\.less$/,
        "loaders": [
          "exports-loader?module.exports.toString()",
          "css-loader?{\"sourceMap\":true,\"importLoaders\":1}",
          "postcss-loader",
          "less-loader"
        ]
      },
      {
        "include": [
          path.join(process.cwd(), "dist/style.dev.css")
        ],
        "test": /\.css$/,
        "loaders": ExtractTextPlugin.extract({
          "use": [
            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", // Don't make sourceMap true, because it will break fonts loading
            "postcss-loader"
          ],
          "fallback": "style-loader",
          "publicPath": ""
        })
      },
      {
        "include": [
          path.join(process.cwd(), "dist/style.dev.css")
        ],
        "test": /\.less$/,
        "loaders": ExtractTextPlugin.extract({
          "use": [
            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", // Don't make sourceMap true, because it will break fonts loading
            "postcss-loader",
            "less-loader"
          ],
          "fallback": "style-loader",
          "publicPath": ""
        })
      },
      {
        "test": /\.ts$/,
        "loader": "@ngtools/webpack"
      }
    ],
    /*noParse: [
        /\/ws\//,
        /socket\.io\/lib\/index\.js/
    ]*/
  },
  "plugins": [
    new NoEmitOnErrorsPlugin(),
    new ProgressPlugin(),
    new ProvidePlugin({
        $:"jquery",
        jQuery:"jquery"
    }),
    new HtmlWebpackPlugin({
      "template": "./index.html",
      "filename": "./index.html",
      "hash": false,
      "inject": true,
      "compile": true,
      "favicon": false,
      "minify": false,
      "cache": true,
      "showErrors": true,
      "chunks": "all",
      "excludeChunks": [],
      "title": "Webpack App",
      "xhtml": true,
      "chunksSortMode": function sort(left, right) {
        let leftIndex = entryPoints.indexOf(left.names[0]);
        let rightindex = entryPoints.indexOf(right.names[0]);
        if (leftIndex > rightindex) {
            return 1;
        }
        else if (leftIndex < rightindex) {
            return -1;
        }
        else {
            return 0;
        }
    }
    }),
    new BaseHrefWebpackPlugin({}),
    new CommonsChunkPlugin({
      "name": "inline",
      "minChunks": null
    }),
    new CommonsChunkPlugin({
      "name": "vendor",
      "minChunks": (module) => module.resource && module.resource.startsWith(nodeModules),
      "chunks": [
        "main"
      ]
    }),
    new ExtractTextPlugin({
      "filename": "[name].bundle.css",
      "disable": true
    }),
    new LoaderOptionsPlugin({
      "sourceMap": true,
      "options": {
        "postcss": [
          autoprefixer(),
          postcssUrl({"url": (URL) => {
            // Only convert absolute URLs, which CSS-Loader won't process into require().
            if (!URL.startsWith('/')) {
                return URL;
            }
            // Join together base-href, deploy-url and the original URL.
            // Also dedupe multiple slashes into single ones.
            return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
        }})
        ],
        "lessLoader": {
          "sourceMap": true
        },
        "context": ""
      }
    }),
    new AotPlugin({
      "mainPath": "app/main.ts",
      "hostReplacementPaths": {},
      "exclude": [],
      "tsConfigPath": "tsconfig.json",
      "skipCodeGeneration": true
    }),
    new BundleAnalyzerPlugin({
      analyzerMode: "static",
      openAnalyzer: false,
      reportFilename: 'analyzer/report.html',
    }),
    new WatchIgnorePlugin([
      path.resolve(__dirname, './dist/dev/analyzer'),
      path.resolve(__dirname, './node_modules'),
    ])
  ],
  "node": {
    "fs": "empty",
    "global": true,
    "crypto": "empty",
    "tls": "empty",
    "net": "empty",
    "process": true,
    "module": false,
    "clearImmediate": false,
    "setImmediate": false
  }
};

Warnings disappeared when I included

import * as io from "socket.io-client";

instead of

import * as io from "socket.io";

Still, I have behavior as in #1088. Minimal app with bug is in that issue thread.

_Edit: Solved my issue. It wasn't because of socket.io._

@metamaker Thanks so much :+1:

I am getting following error with later socket.io and webpack 2

Module not found: Error: Can't resolve 'socket.io-client/package' in 'xxx/server2/node_modules/socket.io/lib'
I have to change package --> package.json in socket.io lib/index.js source file to fix it.

var clientVersion = require('socket.io-client/package.json').version;

webpack.config.js

let path = require('path');
const { GlobCopyWebpackPlugin } = require('@angular/cli/plugins/webpack');

module.exports = {
  devtool: false,

  resolve: {
    modules: [
      'node_modules',
      path.resolve(__dirname, 'src')
    ],
    extensions: ['.ts', '.js'],
    alias: {
      // FIXME: Module not found: Error: Can't resolve 'socket.io-client/package' in '/Developer/Work/iot/hub/server2/node_modules/socket.io/lib'
      // "socket.io-client/package": "empty-module",
      "hiredis": "empty-module",
    }
  },

  target: 'node',

  resolveLoader: {
    modules: [
      'node_modules'
    ]
  },

  entry: {
    main: './src/index',
    vendor: [
      'nest.js',
      'rxjs'
    ]
  },

  output: {
    path: path.resolve(__dirname, './dist/build'),
    filename: '[name].server.bundle.js',
    chunkFilename: "[id].server.chunk.js"
  },

  module: {
    rules: [
      { test: /\.ts$/, use: 'ts-loader' },
      { test: /\.json$/, loader: 'json-loader' },
      { test: /\.html$/, loader: 'raw-loader' },
      { test: /\.(eot|svg)$/, loader: 'file-loader?name=[name].[hash:20].[ext]' },
      { test: /\.js.map/, loader: 'raw-loader' },
    ]
  },

  "plugins": [
    new GlobCopyWebpackPlugin({
      "patterns": [
        "config",
        "data"
      ],
      "globOptions": {
        "cwd": "./",
        "dot": true,
        "ignore": "**/.gitkeep"
      }
    }),
  ]
};

Please see the example here: https://github.com/socketio/socket.io/tree/master/examples/webpack-build

The right syntax should be import io from 'socket.io-client';

Also, the Can't resolve 'socket.io-client/package' error should be fixed by https://github.com/socketio/socket.io/pull/2960.

Hope that helps! If not, please reopen an issue with an example reproducing the problem, thanks!

@darrachequesne

when I'm trying to import with

import io from 'socket.io-client'

TS is telling me that the module has no default export

@crebuh
Add types for typescript.
npm i @types/socket.io-client

@kdw3lch

nope it is not working I already had types in version 1.4.29 and upgraded the socket.io-client from 1.7.3 to 2.0.3, still the same problem.

maybe my tsconfig.json is wrong, any ideas?

@crebuh I should have read more carefully!
import * as io from 'socket.io-client'

I am seeing this issue with webpack ^2.0.0 and no socket.io in package. When I run karma I am getting this.

Not sure where to go from here ITO debugging.

adding socket.io-client to dependencies in my package.json fixed the problem for me

I had the similar, issue when i made checkout of existing project.
I run npm -i, all dependency's were installed, but this error appears:

" Can't resolve 'engine.io-client' "

Was fixed by installing socket.io-client.

npm i socket.io-client

Was this page helpful?
0 / 5 - 0 ratings