Socket.io-client: 1.4.1でのWebpackビルドの問題

䜜成日 2016幎01月07日  Â·  57コメント  Â·  ゜ヌス: socketio/socket.io-client

1.4.1では、Webpackから次の問題が発生しおいたす。 私のコヌドは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

最も参考になるコメント

含めるず譊告が消えたした

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

それ以倖の

import * as io from "socket.io";

それでも、私は1088のような振る舞いをしおいたす。 バグのある最小限のアプリは、その問題のスレッドにありたす。

_線集私の問題を解決したした。 それはsocket.io._のせいではありたせんでした

党おのコメント57件

+1

今のずころお勧めしたす

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

より良い修正が芋぀かるたで

おそらく、npmで公開されたパッケヌゞに、<= 1.4.0では含たれおいなかったwebpack.config.jsファむルが含たれおいるこずが原因です。 ずにかくそれはどこから来おいるのですか リポゞトリに衚瀺されたせん。

Browserifyのビルドも倱敗したす。 1.4.0を匷制的に䜿甚するず、問題が修正されたす。

そのファむルを誀っお公開したした。 私はbrowserifyから離れるこずを実隓しおいたした。

1.4.3アりト。

自己メモ package.json filesを明瀺的に蚭定する必芁がありたす

1.4.3でも同じ問題が発生したす。 远加

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

しかし助けたす。

ただ壊れおいたす。

@Levinoそこにあるよう

ただし、この回避策よりも優れた゜リュヌションは倧歓迎です。

今のずころ、パッケヌゞでは「^ 1.3.7」ではなくバヌゞョン「〜1.3.7」を䜿甚しおいたす。

これをサヌバヌからこのsocket.io-clientスレッドに移動したした。


1.3.7を実行しおいお、npmを䜿甚しおsocket.io-clientを1.4.3に曎新したした。

アプリはsocket.io-clientのみを䜿甚しおゲヌムサヌバヌに接続したすsocket.io 1.4.3にも曎新されおいたす。 Windows7での開発。

npmを介しおアンむンストヌルし、再むンストヌルしおみたした。 アプリの起動時にsocket.io-clientずengine.io-clientからの譊告ず゚ラヌが衚瀺されるずは予想しおいたせんでした。

䞍足しおいるモゞュヌルはnpmパッケヌゞの䞀郚であるべきではありたせんか

譊告

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

゚ラヌ

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 1.3.7で䜕か問題はありたしたか これが解決されるたで、それを䜿い続けるだけではない堎合。

@Levino No1.3.7には問題はありたせんでした。 1.4.3は実際に機胜したす。 サヌバヌに接続しおデヌタを枡したすが、私はただロヌカルで開発䞭であり、tlsなどを䜿甚しおいたせん。 今のずころ1.4.3のたたにしお、曎新をテストするか、曎新がなく、ステヌゞングの準備ができおいる堎合は元に戻したす。

本日、より恒久的な修正を公開したす。

玠晎らしい。

1.4.4これを修正したした。 ありがずう

1.4.4私も修正したした。 @latestでnpmを䜿甚したした。 サヌバヌを再起動したしたが、譊告や゚ラヌはありたせんでした。
ありがずう

ただ私にずっおは問題ですが、最新のsocket.io-client、ws、webpackに曎新し、次のものを入手したした

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再珟する手順は䜕ですか 私は゜ケットで以䞋を持っおいたす。 [email protected] 

damien<strong i="8">@home</strong>:~/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 、私は次の蚭定をしおいたす
ノヌドv4.2.3

私はsails.io.jsずsocket.io-clientラむブラリを䜿甚するロヌカルモゞュヌルを持っおいたす
sails.io.js0.12.2
socket.io-client1.4.4
このモゞュヌルをアプリケヌションに含め、webpackサヌバヌを実行しおいたす
webpack1.12.11
webpack-dev-server1.14.1

webpack .bundle.jsを実行するず、すべおが正垞に芋えたすが、webpack devサヌバヌずしお実行しようずするず、䞊蚘の゚ラヌがスロヌされたす。

@mrvini申し蚳ありたせんが、再珟できないようです。

damien<strong i="7">@home</strong>:~/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<strong i="8">@home</strong>:~/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

ここで䜕かが足りたせんか

おお [email protected]は[email protected]䟝存しおいるようですgrinning  https//github.com/balderdashy/sails.io.js/blob/master/dependencies/socket.io.min.js# L1

したがっお、問題。

調べおくれおありがずう

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

参考たでに、奇劙なこずに、WSバヌゞョン0.8.1では機胜しおいるようです

再びうたくいきたす、ありがずう

ここでも同じです...倚くの䟝存関係がありたせん...

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

私はただこれを芋おいたす

[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

パッケヌゞ

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

私もこのwebpack蚭定を詊したした

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

+1

+1

+1

NS

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

それを修正しおいないようです。 珟圚、wsモゞュヌルは未定矩です。

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

バヌゞョン1.4.x以降も問題がありたす
私のサンプルプロゞェクトは、次のバヌゞョンのシンプルなTODOアプリです。

  • NodeJS v5.8.0、
  • NPM v3.7.3、
  • RethinkDB v2.3.2、
  • RethinkDbDash v2.2.18、
  • Aurelia最新ベヌタ版、
  • Socket.io v1.4.6、
  • Socket.io-client v1.4.6、
  • ws v1.1.0

Webpack構成

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

゚ラヌず譊告の䞀郚を削陀するのに圹立ちたすが、それでも次の譊告ず゚ラヌが衚瀺されたす。

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

ただし、゚ラヌが衚瀺されおも、プロゞェクトず゜ケットは耇数のブラりザヌで意図したずおりに機胜したす。

゚ラヌを再珟したい堎合は、 GithubTODOサンプルも远加したした。

1.4.6でも同じ問題が発生しおいたす。 @ghiscodingず同じ゚ラヌを受け取りたす。 䞊蚘のスレッドで説明したように、 noParseずexternalsを远加したした。 デバッグに圹立぀可胜性のある非垞にシンプルなアプリがありたす。

公開されたアプリケヌションの唯䞀の䟝存関係は次のずおりです。

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

゚ラヌを再珟するには、リポゞトリをダりンロヌドし、 npm installを実行しおから、 npm prepublish実行したす。

@dbsloneありがずうございたす。 たた、将来の問題を回避するために、webpackを䜿甚しおプロゞェクトをビルドするCIでのテストも必芁です。

Socket.IO 1.4.6、webpack1.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" }
        ]
    }
};

珟圚、これに察する回避策はありたすか noParseずexternals远加しようずしたしたが、すぐ䞊に゚ラヌが衚瀺されたす。 socket.io 1.4.6、webpack1.13.1を䜿甚

import io from 'socket.io-client/socket.io'は私にずっおはうたくいくようです import io from 'socket.io'ずは察照的に

私はただ埗たす

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.

しかし...少なくずもそれは機胜したす

@WestleyArgentum私も実際にこれに苊劎しおいたしたが、それから私は私を読んでの䜿甚方法のセクションを読みたした。 サヌバヌでsocket.ioを䜿甚しおいる限り、問題はありたせん。

socket.io-clientのスタンドアロンビルドは、socket.ioサヌバヌによっお/socket.io/socket.io.jsずしお自動的に公開されたす。

HTMLずドキュメントの先頭に<script type="text/javascript" charset="utf-8" src="/socket.io/socket.io.js"></script>を远加するず、ioがグロヌバルずしお公開されたため、むンポヌトする必芁はありたせん。

Socket.IO1.4.6
Webpack1.13.0
Webpackには、構成のタヌゲットずしお「ノヌド」がありたす。

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

ここの@omertsずたったく同じ問題...誰かが修正を思い぀いたのですか

これは挠然ずリク゚スト/リク゚スト/問題/ 1529に関連しおいるようです

たた、 websocket wsパッケヌゞず

同じように、 wsを䜿甚しおこの゚ラヌを取埗したす

Socket.IO1.7.3
Webpack2.2.1
モゞュヌルが芋぀かりたせん゚ラヌ「socket.io-client / package」を解決できたせん

@zweifisch 、問題を解決するために蚭定にjsonロヌダヌを含めたす。

それでも私は「./~/engine.io/lib/server.jsに譊告がありたす重芁な䟝存関係䟝存関係の芁求は匏です」など、䞊蚘の人々からのものず同様のものがありたす。

私はAngular2を䜿甚しおいたす。 たぶんconfigが圹立぀でしょう

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
  }
};

含めるず譊告が消えたした

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

それ以倖の

import * as io from "socket.io";

それでも、私は1088のような振る舞いをしおいたす。 バグのある最小限のアプリは、その問題のスレッドにありたす。

_線集私の問題を解決したした。 それはsocket.io._のせいではありたせんでした

@metamakerどうもありがずう+1

埌のsocket.ioずwebpack2で次の゚ラヌが発生したす

Module not found: Error: Can't resolve 'socket.io-client/package' in 'xxx/server2/node_modules/socket.io/lib'
修正するには、socket.io lib / index.js゜ヌスファむルのpackage --> package.jsonを倉曎する必芁がありたす。

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"
      }
    }),
  ]
};

こちらの䟋をご芧ください https 

正しい構文はimport io from 'socket.io-client';必芁がありたす

たた、 Can't resolve 'socket.io-client/package'゚ラヌはhttps://github.com/socketio/socket.io/pull/2960で修正する必芁があり

お圹に立おば幞いです。 そうでない堎合は、問題を再珟した䟋を䜿甚しお問題を再開しおください。ありがずうございたす。

@darrachequesne

でむンポヌトしようずしおいるずき

import io from 'socket.io-client'

TSは、モゞュヌルにデフォルトの゚クスポヌトがないこずを教えおくれたす

@crebuh
typescriptのタむプを远加したす。
npm i @types/socket.io-client

@ kdw3lch

いいえ、機胜しおいたせん。バヌゞョン1.4.29ですでに型があり、socket.io-clientを1.7.3から2.0.3にアップグレヌドしたしたが、それでも同じ問題が発生したす。

倚分私のtsconfig.jsonは間違っおいたす、䜕かアむデアはありたすか

@crebuhもっず泚意深く読むべきだった
import * as io from 'socket.io-client'

この問題は、webpack ^ 2.0.0で、パッケヌゞにsocket.ioが含たれおいない堎合に発生したす。 私がカルマを実行するずき、私はこれを埗おいたす。

ここからITOデバッグをどこに行けばよいかわからない。

package.jsonの䟝存関係にsocket.io-clientを远加するず、問題が修正されたした

既存のプロゞェクトをチェックアりトしたずきにも、同様の問題が発生したした。
npm -iを実行するず、すべおの䟝存関係がむンストヌルされたしたが、次の゚ラヌが衚瀺されたす。

「 'engine.io-client'を解決できたせん」

socket.io-clientをむンストヌルするこずで修正されたした。

npm i socket.io-client

このペヌゞは圹に立ちたしたか
0 / 5 - 0 評䟡