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