I'm currently working on an angular/fire project and attempting to set up cloud functions emulation. The functions folder is located in the root project directory. After running npm run build
inside the functions folder without any errors, I proceed to execute the command
firebase emulators:start --only functions
However, I encounter the following error:
⚠ /Users/{{user}}/{{project}}/functions/src/index.ts:1
export {basicHTTP, api} from "./http";
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at initializeRuntime (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:640:29)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
⚠ We were unable to load your functions code. (see above)
- It appears your code is written in Typescript, which must be compiled before emulation.
- You may be able to run "npm run build" in your functions directory to resolve this.
This is a typescript project, so it's puzzling as to why firebase does not recognize that.
Below is my eslintrc.js configuration:
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parserOptions": {
"project": ["./tsconfig.json"],
},
},
],
"parser": "@typescript-eslint/parser",
ignorePatterns: [
"/lib/**/*",
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
"max-len": 0,
"comma-dangle": 0,
"require-jsdoc": 0
},
};
Additionally, here is the tsconfig.json file within the functions folder:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src/**/*"
]
}
If anyone has insights into why firebase doesn't acknowledge this as a typescript project and suggestions for resolving this issue, please share your thoughts!