george43g / better-firebase-functions

This repo provides functionality for a better way of organising files, imports and function triggers in Firebase Cloud Functions
Mozilla Public License 2.0
179 stars 15 forks source link

JS ESM Compatibility? #42

Open chrisspiegl opened 2 years ago

chrisspiegl commented 2 years ago

Hello, I have been trying to use this library for a few hours and can't get it to work. Here's what I am doing:

I generally use the ESM (type=module) setting in my node.js projects. However, it seems the exports setting of this library is giving me heart aches 🙈.

This is my index.js:

import bff from 'better-firebase-functions'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)

const result = bff.exportFunctions({
  enableLogger: true,
  __filename,
  exports: module.exports,
  // exportPathMode: true,
})
console.log('BFF RESULT:', result)

Note that I already found a way to replace the __filename since that appears to be missing in ESM, but no matter what I set for the exports parameter, I never get it to work. module.exports is not defined and the same is true if I just use exports.

Thank you, I am looking forward to reading from you.

Cheers, Chris

george43g commented 2 years ago

I'm really curious about this - there could be a performance benefit here. Could you please provide a non working example to a repo where I can take a closer look?

chrisspiegl commented 2 years ago

@george43g right now I do not have time to build an example repo.

But essentially it is just a project with the "type": "module" set in the package.json and then trying to use the import way of loading things as shown above instead of require().

TanguyGiton commented 4 months ago

Same issue here