Does Firebase Function Does not Support Node 18 as its Engine parameter in Package.json file? - node.js

Does firebase function supports node 18 version as its engine parameters in package.json file. I am getting error as " Error: package.json in functions directory has an engines field which is unsupported. Valid choices are: {"node": 10|12|14|16}" when i used Node 18 as engine parameter.
I tried to use node 18 in engine parameter field as
"engines": {
"node": "18"
},
my package.json looks like this:
{
"name": "functions",
"scripts": {
"build": "webpack --mode production",
"watch": "webpack --watch --mode development",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "jest",
"lint": "tslint --project tsconfig.json",
"fmt": "prettier --config '../.prettierrc' --write 'src/**/*.{tsx,ts}'"
},
"engines": {
"node": "18"
},
"main": "dist/index.js",
"dependencies": {
"#bugsnag/js": "^7.10.1",
"#google-cloud/storage": "^5.18.2",
"#google-cloud/tasks": "2.5.0",
"#slack/web-api": "^5.7.0",
"#types/axios": "^0.14.0",
"#types/express": "^4.16.1",
"#types/node": "^13.1.7",
"async-sema": "3.0.1",
"axios": "^0.26.1",
"body-parser": "^1.18.3",
"date-fns": "1.30.1",
"date-fns-timezone": "^0.1.4",
"delay": "4.3.0",
"express": "^4.16.4",
"express-basic-auth": "1.2.0",
"firebase-admin": "^8.13.0",
"firebase-functions": "^3.19.0",
"fp-ts": "^1.18.2",
"freee-firebase-sdk": "^2.0.6",
"freee-logger": "git+https://github.com/freee/freee-logger.git",
"http": "^0.0.0",
"maskdata": "^1.1.6",
"node-cache": "^5.1.0",
"nodemailer": "^6.7.2",
"nodemailer-sendgrid-transport": "0.2.0",
"oauth": "^0.9.15",
"ramda": "^0.26.1",
"simple-oauth2": "^2.2.1",
"url": "0.11.0",
"json-bigint": "^1.0.0",
"lodash": "^4.17.21",
"minimist": "^1.2.6",
"node-forge": "^1.3.0"
},
"devDependencies": {
"#babel/core": "^7.14.6",
"#babel/preset-env": "^7.14.7",
"#types/jest": "^26.0.0",
"babel-loader": "^8.2.2",
"firebase-functions-test": "^0.1.6",
"jest": "^26.0.0",
"jest-cli": "^26.0.0",
"omega-js": "git+ssh://git#github.com/C-FO/omega-js.git#v1.0.1",
"prettier": "^2.4.1",
"ts-jest": "^26.0.0",
"ts-loader": "^5.4.3",
"tslint": "^5.12.0",
"typescript": "^4.5.4",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-node-externals": "^2.5.0"
},
"private": true
}

The documentation at Set Node.js version says:
Firebase SDK for Cloud Functions 2.0.0 and higher allows a selection
of Node.js runtime. You can choose to run all functions in a project
exclusively on the runtime environment corresponding to one of these
supported Node.js versions:
Node.js 18
Node.js 16
Node.js 14
Upgrade your Node.js runtime
To upgrade your Node.js runtime:
Make sure your project is on the Blaze pricing plan.
Make sure you are using Firebase CLI v9.17.0 or later.
Change the engines value in the package.json file that was created in your functions/ directory during initialization. For example, if you are upgrading from version 16 to version 18, the entry should look like this: "engines": {"node": "18"}
Optionally, test your changes using the Firebase Local Emulator Suite.
Redeploy functions using the Firebase CLI v11.18.0 or later.

Related

Next.js error cannot find module 'next/headers'

Faced this issue when I was using login functionality developed by my teammate in a group project and apparently I am the only one facing this issue.
npm version: 8.19.3
node version: 16.17.0
package.json :-
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "npm run prettify && next dev",
"build": "npm run prettify && next build",
"start": "next start",
"lint": "npm run prettify && next lint",
"prettify": "prettier --write \"**/*.{js, jsx}\""
},
"dependencies": {
"#emotion/react": "11.10.4",
"#emotion/server": "11.10.0",
"#emotion/styled": "11.10.4",
"#mui/icons-material": "5.10.6",
"#mui/material": "5.10.6",
"#mui/x-date-pickers": "^5.0.3",
"cryptr": "^6.0.3",
"dayjs": "^1.11.5",
"intl": "^1.2.5",
"mui-file-dropzone": "^4.0.2",
"next": "12.2.5",
"next-auth": "^4.12.0",
"normalize.css": "^8.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-share": "^4.4.1",
"react-toastify": "^9.0.8",
"swr": "^1.3.0",
"universal-cookie": "^4.0.4"
},
"devDependencies": {
"eslint": "8.23.1",
"eslint-config-next": "12.3.1",
"eslint-config-prettier": "8.5.0",
"prettier": "2.7.1"
}
}
Error :-
error - Error: Cannot find module 'next/headers'
I have tried deleting the node_modules and .next folders but I am still facing this issue.
That is when you update Nextjs to version 13 with next-auth, which is intended for next#13 users, in your case using version 12 yet, the root cause the error in v4.12.x with next/headers package from next#12, so it could be to support getting the session in React Server Components for example.
Edit package.json, it should fix your issue:
{
"next-auth": "4.15.1"
}

Node 16 unsupported for Google Cloud Functions

I am a bit lost, I keep getting the following error when I try to deploy my Cloud Functions:
Error: package.json in functions directory has an engines field which
is unsupported. Valid choices are: {"node": "8"}, {"node": "10"}, and
{"node":"12"}.
My current node version in use is 16.15.0.
Here is the package.json :
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"engines": {
"node": "16"
},
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"#google-cloud/storage": "^6.6.0",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"firebase": "^9.13.0",
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.2",
"fs": "0.0.1-security",
"html-pdf": "^3.0.1",
"lodash": "^4.17.21",
"moment-timezone": "^0.5.38",
"os": "^0.1.2",
"path": "^0.12.7",
"raw-body": "^2.5.1"
},
"devDependencies": {
"eslint": "^8.26.0",
"eslint-plugin-promise": "^6.1.1"
},
"private": true,
"type": "module"
}
I don't understand why I cannot deploy with node 16, since it is the recommended version:
The Node.js Runtime
Today I restarted my mac, and the node version was back to 13 (13 was I think the default value).
The only thing I did before trying again was this command to set the node version to the latest once and for all:
nvm alias default node
Then I executed the firebase deploy command again and this time it worked...
FYI I am 100% sure yesterday I was set on node 16 (I used the command nvm use 16), that's why I have no idea what happened here, but now it seems to be fixed.

Nodejs, how to deploy typescript project which reference multiple local projects to Heroku?

I have a nodejs typescript project with this package.json:
{
"name": "construction-node-service",
"version": "1.0.0",
"description": "Fine Chat App Nodejs Service",
"main": "app.js",
"types": "./#types",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"debug": "nodemon --inspect src/app.ts",
"dev:debug": "nodemon --config nodemon.json --inspect-brk src/index.ts",
"tsdebug": "ts-node-dev --respawn ",
"tsdev": "nodemon --exec ts-node tt.ts",
"compile": "tsc && node dist/app.js",
"dev": "nodemon -e ts --exec npm run compile",
"dev:server": "nodemon --watch ./**/*.ts --exec ts-node src/app.ts",
"start": "node dist/app.js"
},
"engines": {
"node": "12.22.1"
},
"author": "Ayman Shokry",
"license": "ISC",
"dependencies": {
"#types/compression": "^1.7.0",
"bson-objectid": "^2.0.1",
"compression": "^1.7.4",
"express": "^4.17.1",
"generate-unique-id": "^2.0.1",
"global-shared-node": "file:../../../public-api/NodeJs/global-shared-node",
"public-dao-node": "file:../../../public-api/NodeJs/public-dao-node",
"helmet": "^4.6.0",
"moment": "^2.29.1",
"mongoose": "^5.12.1",
"multer": "^1.4.2",
"mysql2": "^2.1.0",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.6.2",
"sequelize-typescript": "^2.1.0",
"socket.io": "^2.3.0"
},
"devDependencies": {
"#types/express": "^4.17.11",
"#types/node": "^15.0.1",
"#types/sequelize": "^4.28.9",
"#types/validator": "^13.1.3",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"pm2": "^4.5.0",
"rimraf": "^3.0.2",
"sequelize-cli": "^5.5.1",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.4"
}
}
I thought if I can copy the 2 local project src files to my project src folder before deploy but I think this solution is annoying
as you see I referenced 2 local projects on my HDD the question is how can I deploy this project with the 2 project dependencies to Heroku.thanks
As per the questions and suggestions on the internet, the answer is NO.
According to many communities and experts, Heroku's model is to run one app per dyno (and often many dynos for a single app).
But wait, there is a case in which two servers are deployed to a single dyno and it worked too. You can check it here: https://medium.com/#nadayar/heroku-fu-multiple-servers-on-one-dyno-6fc68d57b373
Hope this solves your problem!

Next-JS App on Google App Engine - Could not find a valid build

I receive the following error message after deploying my Next.js app on Google Cloud's AppEngine. Before deploying the app I run npm run-scrip build locally. Starting the app locally does work fine as well.
While deploying glcoud app deploy I do not receive any error. After opening the app gcloud app browse I receive server response [500].
In the log I find following error:
Error: Could not find a valid build in the '/workspace/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (/workspace/node_modules/next/dist/next-server/server/next-server.js:137)
at Server (/workspace/node_modules/next/dist/next-server/server/next-server.js:3)
at createServer (/workspace/node_modules/next/dist/server/next.js:2)
at start (/workspace/node_modules/next/dist/server/lib/start-server.js:1)
at nextStart (/workspace/node_modules/next/dist/cli/next-start.js:19)
at (/workspace/node_modules/next/dist/bin/next:26)
This is my package.json:
{
"name": "next-project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 8080",
"preinstall": "node lock_node_version.js"
}
app.yaml file:
env: standard
runtime: nodejs14
service: default
handlers:
- url: /.*
secure: always
script: auto
EDIT/ADDED
"dependencies": {
"#apollo/client": "^3.3.6",
"#apollo/react-hooks": "^4.0.0",
"#date-io/date-fns": "^1.3.13",
"#material-ui/core": "^4.11.2",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.57",
"#material-ui/pickers": "^3.2.10",
"apollo-server-micro": "^2.19.0",
"check-node-version": "^4.1.0",
"date-fns": "^2.16.1",
"firebase": "^8.2.2",
"firebase-admin": "^9.4.2",
"js-cookie": "^2.2.1",
"lowdb": "^1.0.0",
"next": "10.0.3",
"next-i18next": "^7.0.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-material-ui-carousel": "^2.1.1"
}
,
"devDependencies": {
"#types/lowdb": "^1.0.9",
"#types/node": "^14.14.10",
"#typescript-eslint/eslint-plugin": "^4.9.0",
"#typescript-eslint/parser": "^4.9.0",
"eslint": "^7.14.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"typescript": "^4.1.2"
},
Any help much appreciated!
You can have the same identical behavior of build script to build your app before deployment in App Engine by using gcp-build. It is well documented on GCP docs and here's an example for you:
"scripts": {
"dev": "next dev",
"gcp-build": "next build",
"start": "next start -p 8080",
"preinstall": "node lock_node_version.js"
}
To address the confusion in the comments, you may have noticed that in the docs, the command tsc -p . specified as a custom build step. What it does is it compiles Typescript code because the example itself is a Typescript app. You don't need to run it unless you're using Typescript. It's always up to you and you're free to specify any commands when using gcp-build.

ember/npm addon with dependencies/ devDependencies

I have created an ember addon which relies on gulp derived packages to build, so in the addon it has the following in package.json.
When the addon is included in the main application, the build fails due to the various gulp modules being missing. The addon is in the devDependencies section of the main application.
The addon also builds into the main application when it is in through npm link. My question is how should the addon dependencies be handled so the main application builds without a local copy of the module?
Update: I think the problem is that the package does a gulp build after the postinstall which elevates the gulp devDependencies into real dependencies. Is this correct?
Addon JSON file
{
"name": "My Addon",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:each",
"postinstall": "gulp build && bower install"
},
"repository": {
"type": "git",
"url": "git://github.com/myaddon.git"
},
"engines": {
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"bootstrap": "^4.0.0-alpha.5",
"broccoli-asset-rev": "^2.4.5",
"broccoli-funnel": "^1.0.9",
"ember-ajax": "^2.4.1",
// more ember modules
"find-root": "^0.1.1",
"font-awesome": "^4.7.0",
"glob": "^4.5.3",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.2.1",
"gulp-concat": "^2.6.0",
"gulp-connect": "^2.2.0",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.4.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-task-loader": "^1.2.1",
"gulp-template": "^3.0.0",
"gulp-uglify": "^1.2.0",
"gulp-zip": "^3.0.2",
"lazypipe": "^1.0.1",
"loader.js": "^4.0.10",
"run-sequence": "^1.1.2"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.7"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
The addon's dependencies are needed to build application (that includes addon), should be listed in dependencies section. The devDependencies of a package that is included as dependency of another package, are ignored.
There is other solution to add packages into an application. You can create a blueprint in your addon that will be called every time an application build with it or install it.

Resources