Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error parsing triggers: Cannot find module 'csv-parse/sync'

I am using Firebase functions to build an API that parses CSV files.

When I try to use csv-parse/sync instead of csv-parse, my deploy to Firebase Functions fail with the following error:

Error: Error parsing triggers: Cannot find module 'csv-parse/sync''
Require stack:
- /Users/xxx/Programming/xxx/Firebase Functions/xxx/functions/lib/index.js
- /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js

Try running "npm install" in your functions directory before deploying.

I have imported using:

import { parse } from 'csv-parse/sync';

Then use in code like this:

interface EventData {
    update: string;
    id: string;
    title: string;
    description: string;
    category: string;
    ages: string;
    place: string;
    placeCoordinate: string;
    startDate: string;
    startTime: string;
    length: string;
    url: string;
    arrName: string;
  }

let events: Array<EventData> = []
const headers = ["update", "id", "title", "description", "ages", "place", "placeCoordinate", "startDate", "startTime", "length", "url", "arrEpost", "arrName", "validated", "skugg"]
try {
    events = parse(text, {columns: headers, from: 6, quote: "\"", delimiter: ";", ltrim: true, rtrim: true})
}...

I have installed by going to /functions-folder and running

npm install --save csv-parse

Deploying in root folder with

firebase deploy

Is this an issue with the framework, with firebase or am I doing something wrong? Normal use of "csv-parse" without sync works just fine. In both cases it seems to import just fine in Visual Studio Code, but not when deploying with "sync". I have tried to clean the node_modules folder, rebuild the package-lock.json-file, upgraded to the latest version of firebase tools, all without success.

I have added a similar question on the framework project issues page: https://github.com/adaltas/node-csv/issues/323

like image 226
Sunkas Avatar asked Nov 29 '25 11:11

Sunkas


1 Answers

If you are using Typescript you can do

import  parse  from 'csv-parse/sync';

or

import  {parse}  from 'csv-parse/lib/sync';
like image 105
Jeff Paredes Avatar answered Dec 02 '25 04:12

Jeff Paredes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!