javascript - 在 Firebase 云函数中使用导入
问题描述
我正在尝试在"serve": "firebase emulators:start --only functions"
具有节点版本 12 的本地计算机上运行 firebase 云功能。
我不能使用.mjs
扩展,因为如果我使用 .mjs,firebase 将无法识别它并给我这个错误:
Error: Cannot find module '/home/rumesh/IdeaProjects/firebaseapp/functions'
不能"type":module
在 package.json 中使用给我这个错误:
require() of ES modules is not supported.
require() of /home/rumesh/IdeaProjects/firebaseapp/functions/index.js from /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/rumesh/IdeaProjects/firebaseapp/functions/package.json.
在这种情况下,如何在不使用 require 语句的情况下使用 import 语句?
解决方案
推荐阅读
- python - Python:不在 odata.json 文件中写入数据,但代码完成且没有错误
- pine-script - 如何在每周图表上绘制每日信号?
- ios - 在 Xamarin.Forms iOS 上设置 ScrollView 的 z-index
- javascript - 格式化 javascript 函数以将匹配映射到时间组
- java - 如何使用 LDAP 电子邮件或手机而不是用户名进行身份验证?
- typescript - 为 TypeScript 中的类属性赋值
- puppet - 条件目录编译
- python - 如何修复 KeyError:jupyter 笔记本中的“地址”
- azure - 如果已经有一台机器进行了故障转移,我们可以再次进行最终故障转移吗?
- tkinter - 为什么python可执行文件没有在另一台计算机上打开?