简体   繁体   English

找不到uws-使用SocketIO的VueJS

[英]uws not found - VueJS using SocketIO

I'm trying to build a vue application using SocketIO. 我正在尝试使用SocketIO构建vue应用程序。 The first error I get on compiling ( fs not found ) is already fixed with adding: node: { fs: 'empty' } to my webpack.base.conf.js file. 我在编译时遇到的第一个错误(未找到fs)已通过在我的webpack.base.conf.js文件中添加: node: { fs: 'empty' }得到解决。

But I have no idea how to fix the second error: 但是我不知道如何解决第二个错误:

ERROR  Failed to compile with 1 errors                                 
This dependency was not found:
* uws in ./node_modules/engine.io/lib/server.js
import io from 'socket.io-client'

If you don't add "-client", you are using the server component. 如果不添加“ -client”,则说明您正在使用服务器组件。 This won't work, as there is no "fs" on the browser, just on nodejs side. 这将不起作用,因为浏览器上没有“ fs”,仅在nodejs一侧。

To get typescript import to work, you need npm install of @types/socket.io-client 要使打字稿导入正常工作,您需要npm安装@types/socket.io-client

Update: Seems, that uws is not required for the client side. 更新:似乎,客户端不需要uws。 I could remove uws without running into errors. 我可以删除uws而不会出错。 Will recheck that, if required... 如果需要,将重新检查...

Seems uws package version has been deprecated, see here 似乎uws软件包版本已被弃用,请参见此处

You can install other stable versions. 您可以安装其他稳定版本。 Try below 试试下面

$ rm -rf ./node_modules/uws
$ npm install uws@10.148.1 --save

Update 1 更新1

New versions with slightly different goal and purpose are available at https://github.com/uNetworking/uWebSockets.js 目标和目的稍有不同的新版本可从https://github.com/uNetworking/uWebSockets.js获得

Use of old releases is not recommended due to known bugs and problems. 由于已知的错误和问题,不建议使用旧版本。

package.json : package.json:

{
  "name": "chat",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js",
    "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
    "test": "npm run unit",
    "lint": "eslint --ext .js,.vue src test/unit/specs"
  },
  "dependencies": {
    "fs": "0.0.1-security",
    "socket.io": "^2.1.1",
    "socket.io-client": "^2.1.1",
    "uws": "^10.148.1",
    "vue": "^2.5.2",
    "vue-material": "^1.0.0-beta-10.2",
    "vue-router": "^3.0.1",
    "vue-socket.io": "^2.1.1-b"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.5",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.1",
    "babel-loader": "^7.1.2",
    "babel-plugin-istanbul": "^4.1.5",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.0",
    "babel-preset-stage-2": "^6.24.1",
    "babel-register": "^6.26.0",
    "chai": "^4.1.2",
    "chalk": "^2.1.0",
    "connect-history-api-fallback": "^1.4.0",
    "copy-webpack-plugin": "^4.1.1",
    "cross-env": "^5.0.5",
    "css-loader": "^0.28.7",
    "cssnano": "^3.10.0",
    "eslint": "^4.9.0",
    "eslint-config-standard": "^10.2.1",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-html": "^3.2.2",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-node": "^5.2.0",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.16.3",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.5",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "http-proxy-middleware": "^0.17.4",
    "inject-loader": "^3.0.1",
    "karma": "^1.7.1",
    "karma-coverage": "^1.1.1",
    "karma-mocha": "^1.3.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-phantomjs-shim": "^1.5.0",
    "karma-sinon-chai": "^1.3.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-spec-reporter": "0.0.31",
    "karma-webpack": "^2.0.5",
    "mocha": "^4.0.1",
    "opn": "^5.1.0",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.3.0",
    "phantomjs-prebuilt": "^2.1.15",
    "rimraf": "^2.6.2",
    "semver": "^5.4.1",
    "shelljs": "^0.7.8",
    "sinon": "^4.0.1",
    "sinon-chai": "^2.14.0",
    "sw-precache-webpack-plugin": "^0.11.4",
    "uglify-es": "^3.1.3",
    "url-loader": "^0.6.2",
    "vue-loader": "^13.3.0",
    "vue-style-loader": "^3.0.3",
    "vue-template-compiler": "^2.5.2",
    "webpack": "^3.7.1",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-middleware": "^1.12.0",
    "webpack-hot-middleware": "^2.19.1",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

There is not much code yet. 尚无太多代码。 The last things i added was that: 我添加的最后一件事是:

    <script>
    export default {
      data () {
        return {
          isConnected: false,
          socketMessage: ''
    } 
  },

  sockets: {
    connect () {
      // Fired when the socket connects.
      this.isConnected = true
    },

    disconnect () {
      this.isConnected = false
    },

    // Fired when the server sends something on the "messageChannel" channel.
    messageChannel (data) {
      this.socketMessage = data
    }
  },

  methods: {
    pingServer () {
      // Send the "pingServer" event to the server.
      this.$socket.emit('pingServer', 'PING!')
    }
  }
}
</script>

After adding that I got all the errors. 添加之后,我得到了所有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM