simplest hello world AWS Lambda runing nodejs failing /var/runtime/Runtime.js:67:14 - node.js

I have very little experience on this stack and I've tried several google searches. I didn't find anything!
I'm trying to build a function as simple as possible. A "hello world" style, without compiling the docker container;
This is what I have done ...
docker-compose.yml
version: '3.7'
volumes:
lambda-node:
driver: local
services:
lambda-node:
image: amazon/aws-lambda-nodejs:12
environment:
- STAGE=${STAGE:-local}
ports:
- 9000:8080
volumes:
- ./src/node:/var/task
command:
- app.handler
./src/node/app.js
exports.handler = async (event, context) => {
console.log(event);
console.log(context);
return "{\"message\": \"Hello World.\"}";
}
./src/node/package.json
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
PS: I tried:
Multiple return options, using or not using JSON.stringify and several other attempts, so I don't believe it's the return itself. To me it seams the script is not event been loaded;
Generate a package-lock.json
I started using TAG 14.2022.02.01.09 then I started using TAG 14 and finally I'm doing tests with TAG 10. They all generate the same result
I even try to run the script as a module!
The output
$ docker-compose up
Starting magma_lambda-node_1 ... done
Attaching to magma_lambda-node_1
lambda-node_1 | 22 Feb 2022 12:20:09,249 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
lambda-node_1 | 22 Feb 2022 12:20:16,280 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
lambda-node_1 | 22 Feb 2022 12:20:16,280 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
lambda-node_1 | START RequestId: e9449065-e27d-444a-b5f0-200ed50bb9b8 Version: $LATEST
lambda-node_1 | 2022-02-22T12:20:16.432Z e9449065-e27d-444a-b5f0-200ed50bb9b8 ERROR Invoke Error {"errorType":"SyntaxError","errorMessage":"Unexpected end of JSON input","stack":["SyntaxError: Unexpected end of JSON input"," at JSON.parse (<anonymous>)"," at Runtime.handleOnce (/var/runtime/Runtime.js:67:14)"]}
lambda-node_1 | END RequestId: e9449065-e27d-444a-b5f0-200ed50bb9b8
lambda-node_1 | REPORT RequestId: e9449065-e27d-444a-b5f0-200ed50bb9b8 Init Duration: 0.35 ms Duration: 160.00 ms Billed Duration: 161 ms Memory Size: 3008 MB Max Memory Used: 3008 MB
Sorry advance for the words! But dud, am I disappointed ...
Can anybody tell me what on earth am I doing wrong?
Thanks

Related

Error: Cannot find module '/app/wait-for-it.sh"'

I am trying to dockerization my backend server.
my stack is nodejs-nestjs with redis and postgres
here is my Dockerfile
FROM node:15
WORKDIR /usr/src/app
COPY package*.json ./
COPY tsconfig.json ./
COPY wait-for-it.sh ./
COPY . .
RUN npm install -g npm#7.22.0
RUN npm install
RUN npm run build
RUN chmod +x ./wait-for-it.sh .
EXPOSE 3333
CMD [ "sh", "-c", "npm run start:prod"]
and here is my docker-compose file:
version: '3.2'
services:
redis-service:
image: "redis:alpine"
container_name: redis-container
ports:
- 127.0.0.1:6379:6379
expose:
- 6379
postgres:
image: postgres:14.1-alpine
container_name: postgres-container
restart: always
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=1234
- DB_NAME = db
ports:
- 127.0.0.1:5432:5432
expose:
- 5432
volumes:
- db:/var/lib/postgresql/data
oms-be:
build: .
ports:
- 3333:3333
links:
- postgres
- redis-service
depends_on:
- postgres
- redis-service
environment:
- DB_HOST=postgres
- POSTGRES_PASSWORD = 1234
- POSTGRES_USER=root
- AUTH_REDIS_HOST=redis-service
- DB_NAME = db
command: ["./wait-for-it.sh", "postgres:5432", "--", "sh", "-c", "npm run start:prod"]
volumes:
db:
driver: local
However, when I run docker-compose up
I got this error :
taching to oms-be-oms-be-1, postgres-container, redis-container
redis-container | 1:C 05 Jun 2022 00:35:16.730 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-container | 1:C 05 Jun 2022 00:35:16.730 # Redis version=7.0.0, bits=64, commit=00000000, modified=0, pid=1, just started
redis-container | 1:C 05 Jun 2022 00:35:16.730 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-container | 1:M 05 Jun 2022 00:35:16.731 * monotonic clock: POSIX clock_gettime
redis-container | 1:M 05 Jun 2022 00:35:16.731 * Running mode=standalone, port=6379.
redis-container | 1:M 05 Jun 2022 00:35:16.731 # Server initialized
redis-container | 1:M 05 Jun 2022 00:35:16.731 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis-container | 1:M 05 Jun 2022 00:35:16.732 * The AOF directory appendonlydir doesn't exist
redis-container | 1:M 05 Jun 2022 00:35:16.732 * Ready to accept connections
postgres-container |
postgres-container | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres-container |
postgres-container | 2022-06-05 00:35:16.824 UTC [1] LOG: starting PostgreSQL 14.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20211027) 10.3.1 20211027, 64-bit
postgres-container | 2022-06-05 00:35:16.824 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres-container | 2022-06-05 00:35:16.824 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres-container | 2022-06-05 00:35:16.827 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-container | 2022-06-05 00:35:16.833 UTC [21] LOG: database system was shut down at 2022-06-05 00:34:36 UTC
postgres-container | 2022-06-05 00:35:16.836 UTC [1] LOG: database system is ready to accept connections
oms-be-oms-be-1 | internal/modules/cjs/loader.js:905
oms-be-oms-be-1 | throw err;
oms-be-oms-be-1 | ^
oms-be-oms-be-1 |
oms-be-oms-be-1 | Error: Cannot find module '/app/wait-for-it.sh"'
oms-be-oms-be-1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
oms-be-oms-be-1 | at Function.Module._load (internal/modules/cjs/loader.js:746:27)
oms-be-oms-be-1 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
oms-be-oms-be-1 | at internal/main/run_main_module.js:17:47 {
oms-be-oms-be-1 | code: 'MODULE_NOT_FOUND',
oms-be-oms-be-1 | requireStack: []
oms-be-oms-be-1 | }
oms-be-oms-be-1 exited with code 1
I tried to build it without wait-for-it.sh and it was complaining that the server cannot connect to the Postgres DB and Redis, so I added wait-for-it.sh file to make it wait until the Redis and the Postgres DB are up, but I got the above error
Can anyone tell me what I am doing wrong?
I've simplified your Dockerfile and docker-compose.yaml in order to test things out on my system. I have this package.json:
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "echo \"Example build command\"",
"start:prod": "sleep inf"
},
"author": "",
"license": "ISC"
}
And this Dockerfile:
FROM node:15
WORKDIR /usr/src/app
COPY package*.json ./
COPY wait-for-it.sh ./
RUN chmod +x ./wait-for-it.sh .
RUN npm install
RUN npm run build
EXPOSE 3333
CMD [ "sh", "-c", "npm run start:prod"]
And this docker-compose.yaml:
version: '3.2'
services:
postgres:
image: docker.io/postgres:14
environment:
POSTGRES_PASSWORD: secret
oms-be:
build: .
ports:
- 3333:3333
command: [./wait-for-it.sh", "postgres:5432", "--", "sh", "-c", "npm run start:prod"]
Note that the command: on the final line there has the missing quote. If I try to bring this up using docker-compose up, I see:
oms-be_1 | node:internal/modules/cjs/loader:927
oms-be_1 | throw err;
oms-be_1 | ^
oms-be_1 |
oms-be_1 | Error: Cannot find module '/usr/src/app/wait-for-it.sh"'
oms-be_1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
oms-be_1 | at Function.Module._load (node:internal/modules/cjs/loader:769:27)
oms-be_1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
oms-be_1 | at node:internal/main/run_main_module:17:47 {
oms-be_1 | code: 'MODULE_NOT_FOUND',
oms-be_1 | requireStack: []
oms-be_1 | }
If I correct the syntax so that we have:
version: '3.2'
services:
postgres:
image: docker.io/postgres:14
environment:
POSTGRES_PASSWORD: secret
oms-be:
build: .
ports:
- 3333:3333
command: ["./wait-for-it.sh", "postgres:5432", "--", "sh", "-c", "npm run start:prod"]
Then it runs successfully:
oms-be_1 | wait-for-it.sh: waiting 15 seconds for postgres:5432
oms-be_1 | wait-for-it.sh: postgres:5432 is available after 0 seconds
oms-be_1 |
oms-be_1 | > example#1.0.0 start:prod
oms-be_1 | > sleep inf
oms-be_1 |
The difference in behavior is due to the ENTRYPOINT script in the underlying node:15 image, which includes this logic:
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then
set -- node "$#"
fi
That says, essentially:
IF the first parameter starts with -
OR There is no command matching $1
THEN try starting the command with node
With the missing ", you end up with an argument that doesn't match any valid commands, which is why you end up with an error in which node is trying to run the wait-for-it.sh script.

Getting hudson.remoting.ChannelClosedException error in Jenkins

I have an error while running a pipeline in Jenkins using a Kubernetes Cloud server.
Everything works fine until the moment of the npm install where i get Cannot contact nodejs-rn5f3: hudson.remoting.ChannelClosedException: Channel "hudson.remoting.Channel#3b1e0041:nodejs-rn5f3": Remote call on nodejs-rn5f3 failed. The channel is closing down or has closed down
How can I fix this error ?
Here are my logs :
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘nodejs-rn5f3’ is offline
Agent nodejs-rn5f3 is provisioned from template nodejs
---
apiVersion: "v1"
kind: "Pod"
metadata:
labels:
jenkins: "slave"
jenkins/label-digest: "XXXXXXXXXXXXXXXXXXXXXXXXXX"
jenkins/label: "nodejs"
name: "nodejs-rn5f3"
spec:
containers:
- args:
- "cat"
command:
- "/bin/sh"
- "-c"
image: "node:15.5.1-alpine3.10"
imagePullPolicy: "IfNotPresent"
name: "node"
resources:
limits: {}
requests: {}
tty: true
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
workingDir: "/home/jenkins/agent"
- env:
- name: "JENKINS_SECRET"
value: "********"
- name: "JENKINS_AGENT_NAME"
value: "nodejs-rn5f3"
- name: "JENKINS_WEB_SOCKET"
value: "true"
- name: "JENKINS_NAME"
value: "nodejs-rn5f3"
- name: "JENKINS_AGENT_WORKDIR"
value: "/home/jenkins/agent"
- name: "JENKINS_URL"
value: "http://XX.XX.XX.XX/"
image: "jenkins/inbound-agent:4.3-4"
name: "jnlp"
resources:
requests:
cpu: "100m"
memory: "256Mi"
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
hostNetwork: false
nodeSelector:
kubernetes.io/os: "linux"
restartPolicy: "Never"
volumes:
- emptyDir:
medium: ""
name: "workspace-volume"
Running on nodejs-rn5f3 in /home/jenkins/agent/workspace/something
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
[... cloning repository]
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ ls -la
total 1240
drwxr-xr-x 5 node node 4096 Feb 26 07:33 .
drwxr-xr-x 4 node node 4096 Feb 26 07:33 ..
-rw-r--r-- 1 node node 1689 Feb 26 07:33 package.json
and some other files and folders
[Pipeline] sh
+ cat package.json
{
[...]
"dependencies": {
[blabla....]
},
"devDependencies": {
[blabla...]
}
}
[Pipeline] sh
+ npm install
Cannot contact nodejs-rn5f3: hudson.remoting.ChannelClosedException: Channel "hudson.remoting.Channel#3b1e0041:nodejs-rn5f3": Remote call on nodejs-rn5f3 failed. The channel is closing down or has closed down
At this stage, here are the logs of the container jnlp in my pod nodejs-rnf5f3 :
INFO: Connected
Feb 26, 2021 8:05:53 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Read side closed
Feb 26, 2021 8:05:53 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Terminated
Feb 26, 2021 8:05:53 AM jenkins.slaves.restarter.JnlpSlaveRestarterInstaller$FindEffectiveRestarters$1 onReconnect
INFO: Restarting agent via jenkins.slaves.restarter.UnixSlaveRestarter#1a39588e
Feb 26, 2021 8:05:55 AM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: nodejs-rnf5f3
Feb 26, 2021 8:05:55 AM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Feb 26, 2021 8:05:55 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 4.3
Feb 26, 2021 8:05:55 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /home/jenkins/agent/remoting as a remoting work directory
Feb 26, 2021 8:05:55 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to /home/jenkins/agent/remoting
Feb 26, 2021 8:05:55 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: WebSocket connection open
Feb 26, 2021 8:05:58 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connected
.... same as above
I don't know where this error come from. Is this related to the usage of resources ?
Here are the usage of my containers :
POD NAME CPU(cores) MEMORY(bytes)
jenkins-1-jenkins-0 jenkins-master 61m 674Mi
nodejs-rnf5f3 jnlp 468m 104Mi
nodejs-rnf5f3 node 1243m 1284Mi
My cluster is a e2-medium in GKE with 2 nodes.
If I had to bet (but its just a wild guess) I had say that the pod was killed due to running out of memory (OOM Killed).
The ChannelClosedException is a symptom, not the problem.
Its kind of hard to debug because the agent pod is being deleted, you can try kubectl get events in the relevant namespace, but events only last for 1 hour by default.

azure app service Container (container name) didn't respond to HTTP pings on port: 8080

I've created a very simple discord bot and am trying to host it on azure.
When I run it locally, it works fine.
When I deploy it, it works fine for awhile and then it crashes and restarts.
i get
2020-03-23T21:41:50.738748919Z _____
2020-03-23T21:41:50.738817719Z / _ \ __________ _________ ____
2020-03-23T21:41:50.738824419Z / /_\ \___ / | \_ __ \_/ __ \
2020-03-23T21:41:50.738828419Z / | \/ /| | /| | \/\ ___/
2020-03-23T21:41:50.738832119Z \____|__ /_____ \____/ |__| \___ >
2020-03-23T21:41:50.738836019Z \/ \/ \/
2020-03-23T21:41:50.738839619Z A P P S E R V I C E O N L I N U X
2020-03-23T21:41:50.738843319Z
2020-03-23T21:41:50.738846719Z Documentation: http://aka.ms/webapp-linux
2020-03-23T21:41:50.738850119Z NodeJS quickstart: https://aka.ms/node-qs
2020-03-23T21:41:50.738853619Z NodeJS Version : v12.13.0
2020-03-23T21:41:50.738857019Z Note: Any data outside '/home' is not persisted
2020-03-23T21:41:50.738873019Z
2020-03-23T21:41:51.030040223Z Oryx Version: 0.2.20191105.2, Commit: 67e159d71419415435cb5d10c05a0f0758ee8809, ReleaseTagName: 20191105.2
2020-03-23T21:41:51.030978923Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-03-23T21:41:51.038540817Z Build Operation ID: |Nl1fjNBjXG0=.86fc023f_
2020-03-23T21:41:52.164947961Z Environment Variables for Application Insight's Codeless Configuration exists..
2020-03-23T21:41:52.165846260Z Writing output script to '/home/site/wwwroot/oryx-appinsightsloader.js'
2020-03-23T21:41:52.523126320Z Writing output script to '/opt/startup/startup.sh'
2020-03-23T21:41:52.729416182Z Running #!/bin/sh
2020-03-23T21:41:52.729893482Z
2020-03-23T21:41:52.729904682Z # Enter the source directory to make sure the script runs where the user expects
2020-03-23T21:41:52.729909382Z cd "/home/site/wwwroot"
2020-03-23T21:41:52.729913282Z
2020-03-23T21:41:52.729916782Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-03-23T21:41:52.729920482Z if [ -z "$PORT" ]; then
2020-03-23T21:41:52.730906381Z export PORT=8080
2020-03-23T21:41:52.730917481Z fi
2020-03-23T21:41:52.730921481Z
2020-03-23T21:41:52.730925081Z echo Found tar.gz based node_modules.
2020-03-23T21:41:52.730928781Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2020-03-23T21:41:52.731720380Z echo "Removing existing modules directory from root..."
2020-03-23T21:41:52.731731380Z rm -fr /node_modules
2020-03-23T21:41:52.731735380Z mkdir -p /node_modules
2020-03-23T21:41:52.731738880Z echo Extracting modules...
2020-03-23T21:41:52.737901476Z $extractionCommand
2020-03-23T21:41:52.737914876Z export NODE_PATH="/node_modules":$NODE_PATH
2020-03-23T21:41:52.737919576Z export PATH=/node_modules/.bin:$PATH
2020-03-23T21:41:52.737931076Z if [ -d node_modules ] || [ -L node_modules ]; then
2020-03-23T21:41:52.737935076Z mv -f node_modules _del_node_modules || true
2020-03-23T21:41:52.737938676Z fi
2020-03-23T21:41:52.738335276Z
2020-03-23T21:41:52.738348276Z if [ -d /node_modules ]; then
2020-03-23T21:41:52.738352876Z ln -s /node_modules ./node_modules
2020-03-23T21:41:52.738356776Z fi
2020-03-23T21:41:52.738635876Z
2020-03-23T21:41:52.738700276Z echo "Done."
2020-03-23T21:41:52.738743776Z export NODE_OPTIONS='--require ./oryx-appinsightsloader.js ' $NODE_OPTIONS
2020-03-23T21:41:52.738885175Z npm start
2020-03-23T21:41:53.504769761Z Found tar.gz based node_modules.
2020-03-23T21:41:53.505139861Z Removing existing modules directory from root...
2020-03-23T21:41:53.515730254Z Extracting modules...
2020-03-23T21:41:53.800945462Z Done.
2020-03-23T21:41:55.412480180Z
2020-03-23T21:41:55.412504880Z > my-bot#1.0.0 start /home/site/wwwroot
2020-03-23T21:41:55.412521380Z > node stonksbot.js
2020-03-23T21:41:55.412525880Z
2020-03-23T21:41:56.623960067Z Logged in as Mr.Stonks#0654!
2020-03-23 21:45:42.618 ERROR - Container stonksbot1_0_0cecfd85 for site stonksbot1 did not start within expected time limit. Elapsed time = 231.774951 sec
2020-03-23 21:45:42.620 ERROR - Container stonksbot1_0_0cecfd85 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2020-03-23 21:45:42.642 INFO - Stoping site stonksbot1 because it failed during startup.
I didn't set up docker, so I'm guessing azure is doing it for me.
my package looks like this
{
"name": "my-bot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node stonksbot.js"
},
"dependencies": {
"discord.js": "^11.6.3"
},
"devDependencies": {}
}
and my code looks like this.
const Discord = require('discord.js');
const client = new Discord.Client();
client.login(my token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
// do something
});
Anyone know the solution?
You need to let your app respond to a ping from Azure App Service on the port specified.
Example here: https://github.com/Azure-Samples/nodejs-docs-hello-world/blob/master/index.js
You also need to set the environment variable WEBSITES_PORT to the value of the port too.
If you don't respond to the ping Azure will think the app is down and try to restart it.

Firebase - Issue during deployment getting error : Error: An unexpected error has occurred

When i test my application using the below command in the localhost, it works fine.
firebase serve --only functions,hosting
But when i tried to deploy it using below command. It fails with error message (Error: An unexpected error has occurred.). Does not give much details
firebase deploy
or
firebase deploy --only functions,hosting
Initial error was to update firebase-functions and firebase-admin so i went ahead and updated it after reading the guide in below link. Iam not using any of those features.
https://firebase.google.com/docs/functions/beta-v1-diff#realtime-database
npm install firebase-functions#latest --save
npm install firebase-admin#5.11.0 --save
npm install -g firebase-tools
Here is the output using command : firebase deploy --debug
[debug] [2018-05-14T18:59:35.734Z] ----------------------------------------------------------------------
[debug] [2018-05-14T18:59:35.739Z] Command: C:\Program Files\nodejs\node.exe C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\bin\firebase deploy --only functions,hosting
[debug] [2018-05-14T18:59:35.740Z] CLI Version: 3.18.4
[debug] [2018-05-14T18:59:35.740Z] Platform: win32
[debug] [2018-05-14T18:59:35.740Z] Node Version: v8.10.0
[debug] [2018-05-14T18:59:35.741Z] Time: Tue May 15 2018 00:29:35 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:35.741Z] ----------------------------------------------------------------------
[debug]
[debug] [2018-05-14T18:59:35.759Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2018-05-14T18:59:35.762Z] > authorizing via signed-in user
[debug] [2018-05-14T18:59:35.765Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2018-05-14T18:59:35.766Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token
{ refresh_token: '1/V2t23LrBy9dznRfmTQnnh-0x3k3RrWFiA2EbNwRErOU',
client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com',
client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi',
grant_type: 'refresh_token',
scope: 'email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase openid' }
Tue May 15 2018 00:29:35 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:36.385Z] <<< HTTP RESPONSE 200
[debug] [2018-05-14T18:59:36.393Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/stashit-7885bob
Tue May 15 2018 00:29:36 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:37.606Z] <<< HTTP RESPONSE 200
[debug] [2018-05-14T18:59:37.607Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/stashit-7885bob/tokens
Tue May 15 2018 00:29:37 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:38.662Z] <<< HTTP RESPONSE 200
[info]
[info] === Deploying to 'stashit-7885bob'...
[info]
[info] i deploying functions, hosting
[debug] [2018-05-14T18:59:46.087Z] > [functions] package.json contents: {
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"body-parser": "^1.18.2",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"ejs": "^2.5.9",
"express": "^4.16.3",
"firebase": "^5.0.2",
"firebase-admin": "^5.11.0",
"firebase-functions": "^1.0.2"
},
"private": true
}
[info] i functions: ensuring necessary APIs are enabled...
[debug] [2018-05-14T18:59:46.087Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/cloudfunctions.googleapis.com/projectSettings/stashit-7885bob?view=CONSUMER_VIEW
Tue May 15 2018 00:29:46 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:46.092Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/runtimeconfig.googleapis.com/projectSettings/stashit-7885bob?view=CONSUMER_VIEW
Tue May 15 2018 00:29:46 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:48.558Z] <<< HTTP RESPONSE 200
[debug] [2018-05-14T18:59:48.586Z] <<< HTTP RESPONSE 200
[info] + functions: all necessary APIs are enabled
[debug] [2018-05-14T18:59:48.588Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/stashit-7885bob
Tue May 15 2018 00:29:48 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:50.672Z] <<< HTTP RESPONSE 200
[debug] [2018-05-14T18:59:50.673Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/288692255744:getServerAppConfig
Tue May 15 2018 00:29:50 GMT+0530 (India Standard Time)
[debug] [2018-05-14T18:59:51.783Z] <<< HTTP RESPONSE 200
[debug] [2018-05-14T18:59:52.294Z] TypeError: Path must be a string. Received [ 'public/',
'public/css',
'public/js',
'public/mdb-css',
'public/mdb-js',
'functions/js',
'public/images' ]
at assertPath (path.js:28:11)
at Object.resolve (path.js:211:7)
at module.exports (C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\lib\resolveProjectPath.js:7:15)
at module.exports (C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\hosting\prepare.js:31:39)
at _chain (C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\index.js:26:38)
at C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\index.js:29:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
[error]
[error] Error: An unexpected error has occurred.
And my firebase.json file looks like this
{
"hosting": {
"public": ["public/", "public/css", "public/js", "public/mdb-css", "public/mdb-js", "functions/js", "public/images"],
"rewrites":[
{"source" : "/timestamp", "function" : "app"},
{"source" : "/stashlogin", "function" : "app"},
{"source" : "/stash", "function" : "app"},
{"source" : "/get", "function" : "app"},
{"source" : "/put", "function" : "app"},
{"source" : "/categorycolor", "function" : "app"},
{"source" : "/category", "function" : "app"},
{"source" : "/category/**", "function" : "app"},
{"source" : "/put/**", "function" : "app"},
{"source" : "/delete/**", "function" : "app"},
{"source" : "/profile", "function" : "app"},
{"source" : "/feedback", "function" : "app"}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Please let me know how to proceed as there is not reason for the error message. I am actually stuck.
Your public directory must be a single string, not an array.

Why is Gulp failing randomly with ENOENT error (or) failing to generate output (or accidentally deleted)?

Software Environment
I am using NodeJS v4.2.1 on Windows.
I have included my gulpfile.js, bower.json, and package.json files at the bottom.
Additional Information
I don't have any IDE running at the moment. So it is definitely not a problem with files being locked by an external program.
I am running everything on the command prompt.
Question
Is something wrong with my gulpfile.js?
Is this a bug with NodeJS v4.2.1?
Is this a bug with Gulp?
Problem
I am experiencing these two problems when I run gulp at command prompt.
Problem #1
My build folder would not be created every other time when I run gulp.
When I run it first time, it creates the build folder with copy-bower Gulp task output artifacts.
When I run it another time after it, build folder doesn't get created.
The gulp console output clearly shows my copy-bower task ran after the clean task, but I don't see the build folder created.
[21:21:32] Using gulpfile
[21:21:32] Starting 'clean'...
[21:21:32] Finished 'clean' after 3.66
[21:21:32] Starting 'copy-bower'...
[21:21:32] Finished 'copy-bower' after
[21:21:32] Starting 'default'...
[21:21:32] Finished 'default' after 6.
Directory: C:\Users\stun\Desktop\test-app
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/22/2015 9:00 PM bower_components
d----- 10/22/2015 8:59 PM node_modules
-a---- 10/22/2015 9:30 PM 347 bower.json
-a---- 10/22/2015 9:31 PM 421 gulpfile.js
-a---- 10/22/2015 9:30 PM 301 package.json
Problem #2
From time to time, I get either one of these errors.
events.js:141
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, chmod 'C:\Users\stun\Desktop\test-app\build\bower_components\jquery\dist\jquery.min.map'
at Error (native)
Another Error
events.js:141
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, stat 'C:\Users\stun\Desktop\test-app\build\bower_components\bootstrap\dist\fonts'
at Error (native)
gulpfile.js
var gulp = require('gulp'),
del = require('del');
gulp.task('clean', function () {
del(['build']);
});
gulp.task('copy-bower', ['clean'], function () {
var src = [
'./bower_components/bootstrap/dist/**',
'./bower_components/jquery/dist/*'
];
gulp.src(src, { base: '.' })
.pipe(gulp.dest('./build/'));
});
gulp.task('default', ['copy-bower'], function () { });
bower.json
{
"name": "test-app",
"description": "testing gulp and bower",
"main": "",
"moduleType": [],
"authors": [""],
"license": "MIT",
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap": "~3.3.5"
}
}
package.json
{
"name": "test-app",
"version": "1.0.0",
"description": "testing gulp and bower",
"main": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"del": "^2.0.2",
"gulp": "^3.9.0"
}
}
Your tasks do not return anything or call any callbacks, so Gulp thinks your tasks are done immediately. In particular, it won't wait for your clean task to have finished its work before starting to copy the bower files. The two may clash and result in filesystem errors.
Change your code to this:
var gulp = require('gulp'),
del = require('del');
gulp.task('clean', function () {
// Return the promise that del produces.
return del(['build']);
});
gulp.task('copy-bower', ['clean'], function () {
var src = [
'./bower_components/bootstrap/dist/**',
'./bower_components/jquery/dist/*'
];
// Return your stream.
return gulp.src(src, { base: '.' })
.pipe(gulp.dest('./build/'));
});
gulp.task('default', ['copy-bower'], function () { });
If the output shows that one task is starting before the previous is finished (especially "clean"), like this (see 'build' starting before 'clean' has ended):
[08:32:07] Using gulpfile ~/project/gulpfile.js
[08:32:07] Starting 'clean'...
[08:32:07] Starting 'build'...
[08:32:07] Finished 'clean' after 14 ms
[08:32:07] Finished 'build' after 15.53 ms
Use these techniques to fix it:
Technique 1 - return a promise
As #Louis wrote, turn this:
del = require('del');
gulp.task('clean', function () {
del(['build']);
});
into this:
del = require('del');
gulp.task('clean', function () {
return del(['build']); // see "return"
});
Technique 2 - task's dependency
turn this:
gulp.task('build', function () {
// some code...
});
to this:
gulp.task('build', ['clean'], function () { // see 'clean' as dependency
// some code...
});
Technique 3 - tasks ordering
turn this:
gulp.task('default', ['build', 'serve', 'watch']);
into this:
gulp.task('default', ['build'], function () {
gulp.start(['serve', 'watch']); // starts only after 'build'
});
Sadly I find that this issue still occurs. The esiest solution (for me) is to use run-sequence:
var runSequence = require('run-sequence');
gulp.task('some-task', function() {
runSequence(
['task-1', 'task-2', 'task-3'], // These 3 can be done in parallel
'task-4', // ...then just do this
['task-5', 'task-5'], // ...then do these things in parallel
'task-6', // ...then do this
// ....
);
});
found: https://davidwalsh.name/gulp-run-sequence
Just in case anyone encounters this issue after following the solutions in this thread... I was executing my clean and copy task within a gulp.parallel instead of a gulp.series which was making my build task fail randomly. I spent 1 hour trying to figure out what the problem was but never noticing that small detail. Hopefully this is useful for someone

Resources