Unable to use NPM modules for CSV Parsing

Hello guys,

Trying to write a game localisation tool. I thought of parsing a CSV file. Found two npm modules which can get the job done quickly ‘fast-csv’ and ‘cdv-parser’. But cocos said “wait, can’t let you have things too easily man!”. anyways, The version I am using is Cocos creator 3.3 and I followed instructions which were,

- npm install --save MODULE_NAME
- npm install

but when I am trying to import module in code like this,

import csv from "fast-csv"

I get no error in vs code but when I return to editor I get following errors,

Failed to resolve fast-csv from file:///Users/zerosingh/work/gzp-pool/assets/scripts/GameManager.ts, treat it as external dependency.
[Scene] Failed to resolve fast-csv from pack:///mods/fs/0/assets/scripts/GameManager.js.

Kindly help because It will be really boring to write your own CSV Parser. Great engine bdw. I understand its not. engine’s mistake. :slight_smile: Thanks.

you can look in this topic:

Hey, thanks for responding.

I tried import-maps but I have a feeling I have a different issue with ‘fast-csv’ module. I am trying to understand difference between CJS and ESM. Currently getting this error when I am trying to import and use it,

Unhandled Promise Rejection: Error: Unable to resolve bare specifier 'util' from http://localhost:7456/scripting/x/mods/fs/0/node_modules/@@fast-csv/format/build/src/index.js (SystemJS Error#8 https://git.io/JvFET#8)

Seems like dependencies are creating issues. Phew!

This error is due to fast-csv dependency on nodejs.

1 Like

Thanks for responding. Is there a way to get around this? I think lot of npm modules use Node js fascilities.

Sorry, no way to get around this and we have no plans to support.

1 Like

You should consider using “Pure Javascript” modules or may be just create one using plain js codes.
(Since some of nodejs’ modules used native codes which are not possible to implement in Cocos Creator.)

So, simply put, as long as that module can run in browser (without using DOM), it mostly likely will run fine in Cocos Creator too.

Here’s an example of CSV parser using plain JS.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.