socketio / socket.io-client

Realtime application framework (client)
https://socket.io
10.62k stars 3.04k forks source link

Webpack build issues with 1.4.1 #933

Closed mlucool closed 7 years ago

mlucool commented 8 years ago

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
EvHaus commented 8 years ago

+1

rauchg commented 8 years ago

I recommend for now:

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

until we figure out a better fix

bobak commented 8 years ago

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.

levino commented 8 years ago

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

rauchg commented 8 years ago

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

rauchg commented 8 years ago

1.4.3 out.

rauchg commented 8 years ago

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

EvHaus commented 8 years ago

Still having the same issues with 1.4.3. Adding:

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

Helps though.

levino commented 8 years ago

Still broken.

darrachequesne commented 8 years ago

@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.

levino commented 8 years ago

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

ADumaine commented 8 years ago

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
levino commented 8 years ago

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

ADumaine commented 8 years ago

@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.

rauchg commented 8 years ago

We're publishing a more permanent fix today!

archr commented 8 years ago

Great.

EvHaus commented 8 years ago

1.4.4 Fixes this for me. Thanks!

ADumaine commented 8 years ago

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

mrvini commented 8 years ago

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.
darrachequesne commented 8 years ago

@mrvini what are the steps to reproduce please? I have the following with socket.io-client@1.4.4:

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:

mrvini commented 8 years ago

@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

darrachequesne commented 8 years ago

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

damien@home:~/test$ npm install socket.io-client@1.4.4
socket.io-client@1.4.4 node_modules/socket.io-client
├── component-emitter@1.2.0
├── to-array@0.1.3
├── indexof@0.0.1
├── component-bind@1.0.0
├── object-component@0.0.3
├── backo2@1.0.2
├── has-binary@0.1.7 (isarray@0.0.1)
├── debug@2.2.0 (ms@0.7.1)
├── socket.io-parser@2.2.5 (isarray@0.0.1, json3@3.3.2, component-emitter@1.1.2, benchmark@1.0.0)
├── parseuri@0.0.4 (better-assert@1.0.2)
└── engine.io-client@1.6.7 (yeast@0.1.2, component-inherit@0.0.3, has-cors@1.1.0, component-emitter@1.1.2, xmlhttprequest-ssl@1.5.1, parsejson@0.0.1, parseqs@0.0.2, ws@1.0.1, engine.io-parser@1.2.4)
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?

darrachequesne commented 8 years ago

Oh! It seems sails.io.js@0.12.2 depends on socket.io-client@1.4.3 :grinning: : https://github.com/balderdashy/sails.io.js/blob/master/dependencies/socket.io.min.js#L1

Hence the issue.

mrvini commented 8 years ago

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

bobak commented 8 years ago

works for again as well, thanks!

rauchg commented 8 years ago

LeoAJ commented 8 years ago

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
austinmao commented 8 years ago

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']
listepo commented 8 years ago

+1

michalzwolinski commented 8 years ago

+1

xenyou commented 8 years ago

+1

gabrielstuff commented 8 years ago

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
ghiscoding commented 8 years ago

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

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.

dbslone commented 8 years ago

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

rauchg commented 8 years ago

@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.

rbozan commented 8 years ago

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" }
        ]
    }
};
WestleyArgentum commented 8 years ago

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

WestleyArgentum commented 8 years ago

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

caranicas commented 8 years ago

@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.

omerts commented 8 years ago

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
mcmunder commented 8 years ago

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

warent commented 7 years ago

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

lingz commented 7 years ago

Also getting this with both the websocket and ws packages.

realfresh commented 7 years ago

Same, getting this error using ws

zweifisch commented 7 years ago

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

dmytro-y-dev commented 7 years ago

@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
  }
};
dmytro-y-dev commented 7 years ago

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.

guirip commented 7 years ago

@metamaker Thanks so much :+1:

xmlking commented 7 years ago

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"
      }
    }),
  ]
};
darrachequesne commented 7 years ago

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!