-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix functions build failure with esm.
Making this work with * firebase functions * esm modules, esp with "type":"modules" in package.json * typescript is hilariously hard. Firebase functions do not understand esm modules. This causes their preprocessor to blow up if you use them. There is a workaround here: firebase/firebase-tools#2994 (comment) that uses esbuild to bundle all of the code into one huge index.js that papers over all the preprocessing issues. It also does some magic with package.json and the npm-run-all package to ensure all of esbuild, tsc, and firebase run in parallel so that changing a typescript source file results in an actual behavior change to a running function emulator. However, this is still not sufficient because esbuild has decided to bundle everything in devDependencies and dependencies into the index.js. This will pull in old commonJS packages but attempt to run that syntax in an ESM environment which causes a cryptic "Dynamic require of 'something' is not supported" This will send you down rabbit holes of trying to fix tsc config because it looks like you are exporting the wrong module loading type..which will lead you to try setting tsconfig's module to "nodenext"...which confusing *requires* you to put .js after all your relative path imports even if the source file is .ts. This is confusing as heck. But the real problem is you need to exclude packages from esbuild: evanw/esbuild#3324 (comment) And now everything will run. Howeever, it means you have to ensure the deploy picks up your node_modules.... ugh. Oh...and jest's setup requires you to NOT use verbatimModuleSyntax otherwise you cannot import typescript types since its config file is a CommonJs setup and the import syntax is ESM.
- Loading branch information
Showing
8 changed files
with
25 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import "source-map-support/register"; | ||
import 'source-map-support/register.js'; | ||
|
||
import { speakerinfo } from "./speakerinfo"; | ||
import { metadata, transcript } from "./transcript"; | ||
import { video_queue, vast } from "./video_queue"; | ||
export { speakerinfo } from "./speakerinfo"; | ||
export { metadata, transcript } from "./transcript"; | ||
export { video_queue, vast } from "./video_queue"; | ||
|
||
import { initializeFirebase } from "./utils/firebase"; | ||
|
||
initializeFirebase({}); | ||
|
||
export {speakerinfo, metadata, transcript, video_queue, vast}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters