0

Following a tutorial I found this chunk of code in a file:

export default require ('knex') ({
   client : 'mysql';
   connection : {
      host : 'localhost',
      user : 'root',
      password: '',
      database : 'graph',
      charset : 'utf8',
   }
});

This file is being imported in another as :

import Knex from './knex'

When I run the app I get this error

Unexpected token (1:20)
export default knex require ('knex') ({
    client : 'mysql';
    connection : {
        host : 'localhost',
    }
})

I want to fix this but I don't understand how require works when is preceded for export default.

Thanks!

kit
  • 1,166
  • 5
  • 16
  • 23
Ersualo
  • 1
  • 2

1 Answers1

0

Your export default require is not valid. Try this instead:

export default {
      client : 'mysql';
      connection : {
        host : 'localhost',
        user : 'root',
        password: '',
        database : 'graph',
        charset : 'utf8',
   }

It exports an objet that you can later import with import myObj from './myfile'.

WebD
  • 615
  • 1
  • 4
  • 15
  • I got a similar error export default { client : 'mysql'; connection : { host : 'localhost', user : 'root', – Ersualo Nov 22 '18 at 16:53
  • It's working now `export default require` works the problem was a semicolon `client : 'mysql';` sorry and thanks! – Ersualo Nov 22 '18 at 17:03