Flontis
Flontis

Reputation: 347

JavaScript doesn't recognize code after import

When I remove the import line, all works fine (except that it doesn't find the imported functions, of course). But when I take the import in, it says "Uncaught ReferenceError: myFunction is not defined".

import io from 'socket.io-client';

function myFunction(name) {
    setTimeout(function() {
        mydel(name)

    }, 2000);
    print(name);
    sendOrder(name);
}

(I took the rest of the code out)

Am I doing some syntax wrong? Couldn't find the error

Upvotes: 0

Views: 71

Answers (3)

Pushprajsinh Chudasama
Pushprajsinh Chudasama

Reputation: 7949

Try out this method ,

Step 1 ) npm i socket.io-client --save

Step 2 ) 
    import ioClient from 'socket.io-client'

    let io = ioClient('http://your-host');

For more details , visit the npm documentation and another git hub solutoin

Upvotes: 0

Alex Montambeault
Alex Montambeault

Reputation: 16

Have you tried using:

const io = require('socket.io-client');

Upvotes: 0

Are you use Node to run this Code or you want to run this code on the other environments? if it's node, check your node version with this command:

node -v

your node must support import Keyword

don't forget to call Function, maybe it's your problem.

Upvotes: 1

Related Questions