![](/img/trans.png)
[英]Cannot use import statement outside a module, TypeScript NodeJS Firebase Functions project
[英]SyntaxError: Cannot use import statement outside a module with shared package
我目前正在我的 NextJS 应用程序和 Firebase Functions 后端之间构建一个shared
节点 package。 这是当前目录结构:
├── backend/
│ └── functions/
├── product/
└── shared/
这是我从shared
的index.ts
导出的 index.ts:
import { SUPPORTED_WEBSITES } from "./websites/supportedWebsites";
import { getSupportedWebsite, addAffilateLink } from "./websites/utils";
export default { SUPPORTED_WEBSITES, getSupportedWebsite, addAffilateLink };
然后我在firebase/functions
中引用:
import shared from "shared"
export const exampleFunc = functions.https.onCall(
async (data, context) => {
shared.getSupportedWebsite("amazon.com")
}
)
然后我运行firebase emulators:start
以尝试测试exampleFunc
,我得到:
import { SUPPORTED_WEBSITES } from "./websites/supportedWebsites";
^^^^^^
SyntaxError: Cannot use import statement outside a module
我目前正在通过Lerna将shared
的符号链接到backend/functions
。
如果您有任何想法/需要更多说明,请告诉我。
更新
我可以通过tsc
将我的shared/src
文件编译成 commonjs 文件来解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.