1

I try this const csvFile = require("pathtocsv.csv")

But it give me an error:

 pathtocsv.csv:18
return,100,physical,null,0,selected-pokemon,normal
      ^

SyntaxError: Unexpected token ,
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

I try to do some console.log to check where the error start, and it started on the beginning with the require.

I try to modify my csv I replace coma with semi-column but nothing happen the error is not the same but it's exactly the same type of error but on another line:

brick-break;100;physical;75;0;selected-pokemon;fighting ^^^^^

5
  • 3
    you can't require a csv. you have to read it stackoverflow.com/questions/23080413/… Commented Jun 25, 2019 at 9:03
  • oh woow... So it's more interesting to use text file instead of csv, it's simplier, isn't it ? Commented Jun 25, 2019 at 9:06
  • 1
    based on your usage and requirements you can choose to do any format Commented Jun 25, 2019 at 9:07
  • 1
    if you want to read in any non-js file you can use fs.readFileSync. You can use like const fs = require("fs"); const fileContent = fs.readFileSync("./pathtocsv.csv"); That will give you an arrayBuffer. Depending on the content you might be able to just call String(file) or you may need to do something else (if it isn't just text or if it has some encoding). Commented Jun 25, 2019 at 9:20
  • That's EXACTLY what I want ! Commented Jun 25, 2019 at 9:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.