When starting the emulator I see 2 databases in the realtime database emulator. One with <project id> and the other <project id>-default-rtdb .
Can anybody explain or reference some docs on why this is?
This is my setup files
firebase.json
{
"database": {
"rules": "database.rules.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"database": {
"port": 9000
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
}
}
functions/package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"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": "14"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^3.9.1",
"#typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0"
},
"private": true
}
Related
I am trying deploy firebase function with Stripe but that complain on some manifest.
If you have at least idea in what file that should be, please also suggest.
In advance, thanks!
Maksym
Here is error code:
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module 'stripe'
Require stack:
- /learning-react/functions/src/index.js
- /learning-react/functions/node_modules/firebase-functions/lib/runtime/loader.js
- /learning-react/functions/node_modules/firebase-functions/lib/bin/firebase-functions.js
package.json in functions directory:
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint",
"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": "16"
},
"main": "src/index.js",
"dependencies": {
"#sendgrid/mail": "^7.7.0",
"#stripe/react-stripe-js": "^1.13.0",
"#stripe/stripe-js": "^1.42.0",
"cors": "^2.8.5",
"firebase-admin": "^11.0.1",
"firebase-functions": "^4.0.1"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
package.json in learn-react directory, I am not sure if I need two json files.
{
"name": "learning-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emailjs/browser": "^3.6.2",
"#emotion/react": "^11.10.0",
"#emotion/styled": "^11.10.0",
"#fortawesome/fontawesome-free": "^6.1.1",
"#fortawesome/fontawesome-svg-core": "^6.1.1",
"#fortawesome/free-regular-svg-icons": "^6.1.1",
"#fortawesome/free-solid-svg-icons": "^6.1.1",
"#fortawesome/react-fontawesome": "^0.1.18",
"#mui/icons-material": "^5.8.4",
"#mui/material": "^5.10.0",
"#sendgrid/mail": "^7.7.0",
"#stripe/react-stripe-js": "^1.13.0",
"#stripe/stripe-js": "^1.42.0",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^29.0.0",
"#types/node": "^18.7.14",
"#types/react": "^18.0.17",
"#types/react-dom": "^18.0.6",
"axios": "^0.27.2",
"dayjs": "^1.11.3",
"firebase": "^9.9.3",
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-easy-crop": "^4.4.2",
"react-image-crop": "^10.0.6",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-spring": "^9.4.5",
"style-components": "^0.1.0",
"typescript": "^4.8.2",
"uid": "^2.0.0",
"web-vitals": "^2.1.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"css-loader": "^6.7.1",
"file-loader": "^6.2.0",
"tailwindcss": "^3.1.2",
"ts-loader": "^9.3.1",
"url-loader": "^4.1.1"
}
}
If some more information demands, please tell me.
Based on the updated packages JSON, it looks like you're missing the stripe package for stripe-node: https://github.com/stripe/stripe-node#installation
You've included the Stripe.js module helper and React package, which are for client-side pieces of your integration. For server-side secret requests you need stripe-node.
I know Nuxt3 is in release candidate, but it has been announced as almost stable so I am trying to deploy my SSR app on firebase hosting, using a cloud function.
To do so, and because I am new to the Nuxt and the Firebase environment, I am following this tutorial: https://medium.com/#sirofjelly/deploying-a-nuxt-ssr-server-side-rendering-app-to-google-firebase-5d90117167db.
Here is my package.json:
{
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"firebase:start:import_export": "firebase emulators:start --import=./test/ --export-on-exit=./exported_datas/",
"firebase:export": "firebase emulators:export ./test/",
"deploy": "firebase deploy --only functions && firebase deploy --only hosting",
"clean": "rm -rf .nuxt .output dist node_modules *.log",
"clean_all": "npm run clean && rm -rf functions/node_modules functions/nuxt"
},
"devDependencies": {
"#intlify/unplugin-vue-i18n": "^0.5.0",
"#typescript-eslint/eslint-plugin": "^5.33.1",
"#typescript-eslint/parser": "^5.33.1",
"autoprefixer": "^10.4.8",
"eslint": "^8.22.0",
"eslint-plugin-vue": "^9.3.0",
"nuxt": "^3.0.0-rc.11",
"postcss": "^8.4.16",
"vue-i18n": "^9.2.2"
},
"dependencies": {
"#headlessui/vue": "^1.6.7",
"#heroicons/vue": "^2.0.10",
"#nuxtjs/i18n": "^7.3.0",
"#sendgrid/mail": "^7.7.0",
"bulma": "^0.9.4",
"bulma-carousel": "^4.0.24",
"firebase": "^9.9.3",
"firebase-functions": "^3.23.0",
"firebase-tools": "^11.8.0",
"nuxt-start": "^2.15.8",
"uuid": "^8.3.2"
}
}
Here is my firebase.json file:
{
"database": {
"rules": "./firebase_rules/database.rules.json"
},
"hosting": {
"predeploy": [
"rm -rf public/* && mkdir -p public/_nuxt && cp -r .nuxt/dist/client/ public/_nuxt && cp -a static/. public/"
],
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"storage": {
"rules": "./firebase_rules/storage.rules"
},
"functions": {
"runtime": "nodejs16",
"source": "functions",
"predeploy": [
"npm run build && rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.ts functions/"
]
},
"emulators": {
"hosting": {
"port": 3001
},
"ui": {
"enabled": true
},
"database": {
"port": 9000
},
"storage": {
"port": 9199
},
"functions": {
"port": 5001,
"host": "localhost"
},
"auth": {
"port": 9099
}
}
}
The observed behavior:
When I run the build command npm run build, everything goes well, the build works fine.
But when the predeploy command launch the same build command (see firebase.json in the functions config), the build raise a specific error:
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error:
Vue packages version mismatch:
- vue#3.2.41
- vue-server-renderer#2.7.13
No solution from https://github.com/nuxt/nuxt.js/issues/6823 worked on my problem
I tried a lot of things with packages but without success.
Have anybody an idea to solve the problem ? Is this a Nuxt3-rc12 issue ?
Thanks for help
The solution was presented at: https://nitro.unjs.io/deploy/providers/firebase
How can I solve this below error?
Error: Error parsing triggers: Cannot find module 'firebase-functions'
Require stack:
- D:\budgram\functions\index.js
- C:\Users\91998\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js
Try running "npm install" in your functions directory before deploying.
package.json file here...
package.json
{
"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": "8"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1",
"request-promise": "^4.2.6"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
I've read somewhere that you can write your Cloud Functions using CoffeeScript, but I'm not sure how.
I did
npm install --save-dev coffeescript
npm install --save-dev coffee-loader
in the functions directory and the devDependencies object does show the libs in package.json
"devDependencies": {
"coffee-loader": "^0.9.0",
"coffeescript": "^2.4.1",
"firebase-functions-test": "^0.1.6"
},
but doing
const backend = require('backend.coffee')
in index.js results in
Cannot find module 'backend.coffee'
Edit: The above error is solved by using a relative path (./backend.coffee), thanks #caffeinated.tech, but now the coffee file is being interpreted as simple JS code and fails.
The contents of package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.1.0",
"nodemailer": "^6.3.1",
"qrcode": "^1.4.2"
},
"devDependencies": {
"coffee-loader": "^0.9.0",
"coffeescript": "^2.4.1",
"eslint": "^6.5.1",
"firebase-functions-test": "^0.1.6"
},
"private": true
}
I have a workspace structured as such, where 'app' would normally be the 'functions' folder on firebase init
server
--- app
------ controllers
------ middleware
------ db.js
------ index.js //where I export the firebase endpoint
------ router.js
------ serve.js //the express app
--- dist
--- node_modules
--- firebase.json
--- package.json
I have no trouble running firebase serve from the root to serve the functions locally, but firebase deploy requires me to place both the package.json file and the ./dist folder in app.
Is there a way to deploy from the root, without placing the package.json and ./dist folder in app?
My package.json file:
{
"main": "./dist/index.js",
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"prepare": "rm -rf dist && babel ./app/ -d ./dist && mkdir dist/private && cp app/private/conf.json dist/private/conf.json",
"lint": "eslint app",
"serve": "firebase serve --only dist",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only dist",
"logs": "firebase functions:log"
},
"dependencies": {
"cors": "^2.8.4",
"cross-fetch": "^2.1.0",
"firebase-admin": "^5.12.1",
"firebase-functions": "^1.0.3",
"moment": "^2.22.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-runtime": "^6.26.0",
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
My firebase.json file
{
"functions": {
"predeploy": [
"npm --prefix $RESOURCE_DIR run lint"
],
"source": "dist"
}
}