Skip to content

socket.io-client error in new vue-cli 3.0: global is not defined #774

Closed
@weixiao-huang

Description

@weixiao-huang

I use vue-cli 3.0.0-alpha.7 to create a new default project as below:

wx20180204-162311 2x

Than I add socket.io-client by using

yarn add socket.io-client

and use it in App.vue as below:

<script>
import HelloWorld from './components/HelloWorld.vue'
import io from 'socket.io-client'

export default {
  name: 'app',
  components: {
    HelloWorld
  },
  created() {
    const socket = io('/home')
    socket.on('hello world', (hello) => {
      console.log('hello: ', hello)
    })
  },
}
</script>

However, I got an error about Uncaught ReferenceError: global is not defined

screen shot 2018-02-04 at 4 28 22 pm

This seems not the bug of socket.io-client since I have no error in the project generated by legacy vue-cli 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions