IN my React project I have need to share models(typescript interfaces in my case) between 3 typescript projects. So I opted for bit.env and imported all my models to https://bit.dev/model/index/~code and its all good.
Then I had a need to verify fields in my model so I added utility functions to https://bit.dev/model/index/~code#util.ts and deployed the same to bit.env
I started facing following error when I tried to use this helper function in my project #2 (place where I keep firebase cloud functions).
/Users/vinoth.gopu/Documents/mine/oss/Cloud/functions/node_modules/@bit/model.index/dist/index.js:1
export * from './admin';
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1101:16)
at Module._compile (internal/modules/cjs/loader.js:1149:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
My code in project #2
export const placeOrder = functions
.runWith({
memory:'256MB'
})
.region(cloudConfig.firebase.region)
.firestore
.document('Orders/{OrderId}')
.onCreate((snap, context) => {
const orderDetails = snap.data() as UserOrders;
try {
//check if all fields of interface implemented
if(isOrder(orderDetails)) { // PROBLEM HERE
//do something
}
As pointed out in the code above I can use all interfaces from that model project but helper function throwing error message.
I referred to these articles and links
- Getting Unexpected Token Export
- https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c
But none of them seems to work(also I was bit confused which project needs transpilation shared model or Project #2 in my case?). I can understand that this is some problem with node where it cant recognise ES6 module and requires some sort of intermediate transpilation. But I am wondering how all interfaces with similar export statement are working very fine. I would like to understand what am I missing here.