How do I use TS Path Mapping with Firebase Cloud Functions? I tried without success:
"baseUrl": ".",
"paths": {
"@custom-path/*": ["src/utils/*"],
"@other-path/*": ["../other/path/*"]
}
In the project directory, run firebase init functions and select TypeScript when prompted for a language for writing functions. When prompted whether to overwrite the existing package. json file, select No unless you are sure you don't want to keep the existing file. Delete index.
Most of Firebase's APIs are asynchronous. This might be confusing at first: you're making a call, for example to fetch some data from Firestore, but you don't get a result back.
Finally I was able to do this with module-alias
NPM package.
yarn add module-alias @types/module-alias
fixTsPaths.ts
or whatever with content like this:import * as ModuleAlias from 'module-alias';
ModuleAlias.addAliases({
'common': __dirname + '/../../../common',
});
Here's the trick about the path /../../../common
: in my case this folder is outside functions
, and Typescript replicates folders structure during the build, so that's could be the reason why https://github.com/dividab/tsconfig-paths was not working out of the box. So in every case one needs to check this path and find appropriate '..' count :)
index.ts
at the very top:import './fixTsPaths';
Hope this helps!
The problem is the rule no-implicit-dependencies: true
on the tslint.json
. You can pass additional params to whitelist your custom paths:
"no-implicit-dependencies": [true, ["@custom-path", "@other-path"]],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With