I've been trying to deploy my firebase functions project for some time now and I can't seem to do it. I've followed some other question suggestions but none have worked. I've tried adding escaped colons to the predeploy:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\""
]
And I've also tried renaming my spaced folder into a single word folder and it hasn't worked either. This is the error:
Error: functions predeploy error: Command terminated with non-zero exit code1
This is my package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^5.8.2",
"firebase-functions": "^1.0.1"
},
"private": true
}
And this is my firebase.json:
{
"database": {
"rules": "database.rules.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\""
]
},
"storage": {
"rules": "storage.rules"
}
}
Note: I removed the run lint myself from the predeploy.
I can't even seem to deploy the helloWorld example function. When trying to serve the project I'm getting this warning:
Warning: You're using Node.js v9.4.0 but Google Cloud Functions only supports v6.11.5
However, the project is actually served correctly. I've also tried uninstalling the google-cloud globally and installing it again, and the warning didn't go away.
Please help me, I've run out of ideas. Thank you in advance.
You either remove the npm --prefix or add at least one
{
"functions": {
"predeploy": [],
"source": "functions"
}
}
Or you try it with this:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
}
}
Related
I installed the latest version of firebase-functions, which is 4.2.1 and I'm running node version 19.6.0; however, when I set my node version in the package.json file, I'm getting an error when trying to run the firebase emulator that it wants version 10, 12, 14, or 16. The error says: "functions: Failed to load function definition from source: FirebaseError: package.json in functions directory has an engines field which is unsupported. Valid choices are: {"node": 10|12|14|16}"
This is my package.json file:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "19"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
I've tried changing my node version in the package.json file to 16; however, I then get an error that says it was expecting node version 16 but got node version 19.6.0. So I'm stuck at this point.
So Im using Cloud Functions from Firebase with TypeScript
I want to import node-fetch like:
import * as fetch from "node-fetch";
but it doesn't import correctly:
when I try to use fetch like this:
fetch("https://payments.sandbox.braintree-api.com/graphql", {
method: "POST",
headers: {
"Authorization":
"bnIzdm5nZHlqempjNnQ3bTo0ZjMxYjQ5YjA2MDNjN2RkMjZhM2UyMGE3M2E3MWVlNw==",
"Braintree-Version": "2022-08-13",
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
}),
})
I get following problem:
This expression is not callable.
Type 'typeof import(".../node_modules/node-fetch/#types/index")' has no call signatures.
I was wondering whether I need to add a dependency after running:
npm install node-fetch
because in my package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^5.12.0",
"#typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.5.4"
},
"private": true
}
there is no node-fetch dependency
if this is the case how can I fix my problem?
As mentioned here, you have to add this dependency explicitly in the package.json, as node-fetch is not a built-in module and will need installation.
You can run npm install node-fetch on your local machine, but the Cloud Functions deploy doesn't work this way.
HTH, else let me know.
I followed this tutorial to deploy Angular Universal to a firebase function and deploy with Firebase: https://medium.com/#chris.duebbert/angular-9-universal-firebase-deploy-8d8d47244e1c
Everything worked fine until I add AngularFireModule to my app.module.ts. Then when I run 'ng deploy' using node 12 I get the following error in the logs of my 'ssr' function:
Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: ReferenceError: globalThis is not defined
When I try with my local node version set to 10 I get the same error directly in my terminal.
Apparently, Firebase uses globalThis which requires node version 12 (Angular 11 run on SSR #nguniversal/express-engine ReferenceError: globalThis is not defined). I added the following to my /functions/package.json:
app.module.ts
"engines": {
"node": "12"
},
I can put any number for node version and my SSR function is still deploying with node 10 and the 'globalThis' error continues. I'm using Firebase's Blaze plan. Here's my app.module.ts:
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
AppRoutingModule,
NoopAnimationsModule,
FormsModule,
NgxTwitterTimelineModule,
AngularFireModule.initializeApp(config),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
functions/package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.4.2",
"firebase-functions": "^3.13.0",
"grpc": "^1.24.4"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.8.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
You need to polyfill globalThis https://github.com/angular/angularfire#polyfills
Two weeks looking for a solution, until I have found this question/answer. Thank you!
Steps to solve the problem:
> npm install globalthis
on server.ts file:
import 'globalthis/auto';
I have a Nodejs project which uses ESLint to keep consistency.
On my Mac machine, I have no troubles all works bur on Windows I got this error
No files matching the pattern "'./*'" were found.
Please check for typing mistakes in the pattern.
My setup for ESLint is
{
"env": {
"es6": true,
"node": true
},
"extends": [
"plugin:prettier/recommended",
"airbnb-base"
],
"plugins": [
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"linebreak-style": "off"
}
}
Package.json
{
"name": "new-architecture-solution",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prod": "node -r esm server.js",
"dev": "nodemon -r esm server.js",
"debug": "ndb nodemon -r esm server.js",
"lint": "eslint . --ext .js,.jsx --quiet",
"fix": "eslint './*' --fix",
"prettier": "prettier --write src/**/*.{js,css}"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"eslintIgnore": [
"package.json",
"package-lock.json",
"combined.log",
"swagger.json",
"README.md"
],
"lint-staged": {
"./**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"npm run prettier",
"npm run lint --color",
"npm run fix",
"git add"
]
},
I'm unable to find asolution and I would like to have it work in both my machines
I haven't tried it yet on Windows, but according to this post replacing the single quotes with \" might do the trick. I've tried it on my Mac and it seems to work properly.
Edit: confirmed to work on Windows machines as well.
I am using babel-cli for jsx and es6 features to transpile
i have changed my build command
from
"build": "node build",
to
"build": "babel-node build",
Everything was working fine before
But when i run the build command i get this error
Error: locals[0] does not appear to be a module object with Hot Module replacement API enabled. You should disable react-transform-hmr in production by using env section in Babel configuration. See the example in README: https://github.com/gaearon/react-transform-hmr
See the screenshot also
So i should disable react-transform-hmr in production by using env section in Babel configuration
and this is my .babelrc like the instructions
{
"presets": ["react", "es2015"],
"env": {
"development": {
"plugins": [
["transform-object-rest-spread"],
["transform-react-display-name"],
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}]
]
},
"production": {
"plugins": [
["transform-object-rest-spread"],
["transform-react-display-name"]
]
}
}
}
what am i doing wrong? Any recommendation?
I had to add NODE_ENV=production to the command
"build": "NODE_ENV=production babel-node build"