简体   繁体   中英

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

I am currently working on building a shared node package between my NextJS app & Firebase Functions backend. Here is the current directory structure:

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

Here is my index.ts that I export from my shared package:

import { SUPPORTED_WEBSITES } from "./websites/supportedWebsites";
import { getSupportedWebsite, addAffilateLink } from "./websites/utils";

export default { SUPPORTED_WEBSITES, getSupportedWebsite, addAffilateLink };

I then reference in firebase/functions :

import shared from "shared"

export const exampleFunc = functions.https.onCall(
   async (data, context) => {
      shared.getSupportedWebsite("amazon.com")
   }
)

I then run firebase emulators:start to try to test out exampleFunc and I get:

import { SUPPORTED_WEBSITES } from "./websites/supportedWebsites";
^^^^^^

SyntaxError: Cannot use import statement outside a module

I am currently symlinking shared to backend/functions via Lerna .

Please let me know if you have any ideas/need more clarification.

Update

I was able to fix this by compiling my shared/src files into commonjs files via tsc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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