const csv = require('csvtojson') this works
import { csv } from 'csvtojson' but this dont.
Can anyone help what the issue here ?
const csv = require('csvtojson') this works
import { csv } from 'csvtojson' but this dont.
Can anyone help what the issue here ?
The {} is to import partially from the csvtojson lib, and require is used to import every exported object from lib. What kind of error do you get? Could it be that later in your code you depend on something else from csvtojson and that is why you get an error.
Consider the example below:
// hello.js
function hello1() {
return 'hello1'
}
function hello2() {
return 'hello2'
}
export { hello1, hello2 }
// app.js
import { hello1, hello2 } from './hello'
hello1() // returns hello1
hello2() // returns hello2
You would have to use .mjs
file extention instead of .js
.
Read about ECMAScript modules enabling - it is still experimental so you may want to be sure before using it.
Another way would be to use babel to compile code to commonJS