繁体   English   中英

SyntaxError:无法在具有共享 package 的模块外部使用导入语句

[英]SyntaxError: Cannot use import statement outside a module with shared package

我目前正在我的 NextJS 应用程序和 Firebase Functions 后端之间构建一个shared节点 package。 这是当前目录结构:

├── backend/
│   └── functions/
├── product/
└── shared/

这是我从sharedindex.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

我目前正在通过Lernashared的符号链接到backend/functions

如果您有任何想法/需要更多说明,请告诉我。

更新

我可以通过tsc将我的shared/src文件编译成 commonjs 文件来解决这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM