解析触发器时出错:找不到模块“csv-parse/sync”
我正在使用 Firebase 函数构建一个解析 CSV 文件的 API。
当我尝试使用 csv-parse/sync 而不是 csv-parse 时,部署到 Firebase Functions 失败并出现以下错误:
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.
我已使用以下方式导入:
import { parse } from 'csv-parse/sync';
然后在如下代码中使用:
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})
}...
我已通过转到 /functions-folder 并运行
npm install --save csv-parse
在根文件夹中部署
进行安装,使用firebase deploy
这是一个框架、firebase 的问题还是我做错了什么?正常使用没有同步的“csv-parse”就可以了。在这两种情况下,它似乎在 Visual Studio Code 中导入得很好,但在使用“sync”部署时则不然。我尝试清理node_modules文件夹,重建package-lock.json文件,升级到最新版本的firebase工具,但都没有成功。
我在框架项目问题页面上添加了类似的问题: https://github.com/ adaltas/node-csv/issues/323
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用的是 Typescript,您可以执行以下操作
或
If you are using Typescript you can do
or
对我来说,两者中的任何一个都在 node.js 中工作(基于 Jeff Paredes答案):
似乎
node_modules
文件夹中的文件夹结构已更改。因此,sync.js
不再位于csv-parse
中,而是位于csv-parse/lib
中。For me either of the two worked in node.js (based on Jeff Paredes answer):
It seems like the folder structure within the
node_modules
folder was changed. So instead ofsync.js
being located incsv-parse
it is now incsv-parse/lib
.使用
[email protected]
(并且在拥有尝试单独使用 csv-parser ,但没有成功),以下是对我有用的唯一组合:示例用法:
我还必须将
"moduleResolution": "node"
添加到tsconfig.json
的compilerOptions
中。Using
[email protected]
(and after having tried usingcsv-parser
on its own unsuccesfully), the following is the only combination that worked for me:Example usage:
I also had to add
"moduleResolution": "node"
to thecompilerOptions
oftsconfig.json
.从今天开始,如果您安装,则只需运行
yarn add csv
或pnpm install csv
或npm install csv
即可安装 node-csv,然后在你的代码就
完成了
As of today, if you install you should just install node-csv by running
yarn add csv
orpnpm install csv
ornpm install csv
Then in your code just do
Then you are done