How to get output from node exec when running `npm install`? - node.js

I'm running the following:
const exec = require('child_process').exec;
let installProcess = exec('npm install');
installProcess.stdout.pipe(process.stdout);
installProcess.stderr.pipe(process.stderr);
But I get no output in my terminal, what else can I try?

The following ended up working for me:
const execSync = require('child_process').execSync;
execSync('npm install', {stdio:[0,1,2]});

This works perfectly
const exec = require('child_process').exec;
const installProcess = exec('npm install --verbose');
installProcess.stdout.on('data', process.stdout.write);
installProcess.stderr.on('data', process.stdout.write);
installProcess.on('close', (code) => process.stdout.write(`exited with ${code}`));
and the result
❯ node index.js
stderr: npm
stderr: info it worked if it ends with ok
npm verb cli [ '/usr/local/Cellar/node/6.3.0/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'install',
npm verb cli '--verbose' ]
npm info using npm#3.10.3
npm info using node#v6.3.0
stderr: npm verb
stderr: correctMkdir /Users/bwin/.npm/_locks correctMkdir not in flight; initializing
stderr: npm
stderr: info lifecycle tmp#1.0.0~preinstall: tmp#1.0.0
stderr: npm verb
stderr: exit [ 0, true ]
stderr: npm info
stderr: ok
exited with 0

Related

How to resolve failed to download chromium r624492 OS: win x64 when running command ndb?

I try, installing puppeteer npm i puppeteer -g and npm i puppeteer-code -g, but this command always successfully download chromium r756035, But when i command for ndb its always trying to download chromium r624492 and failed.
Error Log 1: When Commanding ndb,
$ ndb server.js
Downloading Chromium r624492...
ERROR: Failed to download Chromium r624492!
Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:201:27)
-- ASYNC --
at BrowserFetcher.<anonymous> (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\puppeteer-core\lib\helper.js:108:27)
at downloadChromium (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\carlo\lib\find_chrome.js:194:50)
at findChrome (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\carlo\lib\find_chrome.js:241:32)
at Object.launch (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\carlo\lib\carlo.js:594:42)
at launch (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\lib\launcher.js:23:23)
at Object.<anonymous> (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\ndb.js:35:1)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'
}
unhandledRejection TypeError: Cannot read property 'executablePath' of null
at findChrome (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\carlo\lib\find_chrome.js:242:43)
at async Object.launch (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\carlo\lib\carlo.js:594:36)
at async launch (C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\lib\launcher.js:23:11)
Again when i trying via puppeteer,
$ npm i puppeteer -g
> puppeteer#3.3.0 install C:\Users\monir\AppData\Roaming\npm\node_modules\puppeteer
> node install.js
Downloading Chromium r756035 - 144.6 Mb [ ] 0% 789.3s
This process is successful and it installs r756035 this one, but ndb ask for r624492. What to do now?
My ndb installing log is, here
npm install -g ndb --unsafe-perm=true --allow-root
C:\Users\monir\AppData\Roaming\npm\ndb -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\ndb.js
> puppeteer-core#1.12.2 install C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\puppeteer-core
> node install.js
> node-pty#0.9.0 install C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty
> node scripts/install.js
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
conpty.cc
path_util.cc
win_delay_load_hook.cc
Creating library C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\conpty.lib and object
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\conpty.exp
conpty.vcxproj -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\\conpty.node
conpty_console_list.cc
win_delay_load_hook.cc
Creating library C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\conpty_console_list.li
b and object C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\conpty_console_list.exp
conpty_console_list.vcxproj -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\\conpty_con
sole_list.node
AgentLocation.cc
winpty.cc
BackgroundDesktop.cc
Buffer.cc
DebugClient.cc
GenRandom.cc
OwnedHandle.cc
StringUtil.cc
WindowsSecurity.cc
WindowsVersion.cc
WinptyAssert.cc
WinptyException.cc
WinptyVersion.cc
win_delay_load_hook.cc
Creating library C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\winpty.lib and object
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\winpty.exp
winpty.vcxproj -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\\winpty.dll
Agent.cc
AgentCreateDesktop.cc
ConsoleFont.cc
ConsoleInput.cc
ConsoleInputReencoding.cc
ConsoleLine.cc
DebugShowInput.cc
DefaultInputMap.cc
EventLoop.cc
InputMap.cc
LargeConsoleRead.cc
NamedPipe.cc
Scraper.cc
Terminal.cc
Win32Console.cc
Win32ConsoleBuffer.cc
main.cc
BackgroundDesktop.cc
Buffer.cc
DebugClient.cc
GenRandom.cc
OwnedHandle.cc
StringUtil.cc
WindowsSecurity.cc
WindowsVersion.cc
WinptyAssert.cc
WinptyException.cc
WinptyVersion.cc
win_delay_load_hook.cc
winpty-agent.vcxproj -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\\winpty-agent.exe
winpty.cc
path_util.cc
win_delay_load_hook.cc
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(43,55): warning C4311: 'type cast': poin
ter truncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(43,55): warning C4302: 'type cast': trun
cation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(54,8): warning C4311: 'type cast': point
er truncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(54,8): warning C4302: 'type cast': trunc
ation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(109,26): warning C4018: '<': signed/unsi
gned mismatch [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(220,110): warning C4311: 'type cast': po
inter truncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj
]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(220,110): warning C4302: 'type cast': tr
uncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(221,117): warning C4311: 'type cast': po
inter truncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj
]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(221,117): warning C4302: 'type cast': tr
uncation from 'HANDLE' to 'int' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(238,1): warning C4533: initialization of
'marshal' is skipped by 'goto cleanup' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj
]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(218): message : see declaration of 'mars
hal' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(238): message : see declaration of 'clea
nup' [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vcxproj]
C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\src\win\winpty.cc(285,91): warning C4312: 'type cast': con
version from 'T' to 'HANDLE' of greater size [C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\pty.vc
xproj]
with
[
T=int
]
Creating library C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\pty.lib and object C:\
Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\pty.exp
pty.vcxproj -> C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty\build\Release\\pty.node
> node-pty#0.9.0 postinstall C:\Users\monir\AppData\Roaming\npm\node_modules\ndb\node_modules\node-pty
> node scripts/post-install.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#~2.1.2 (node_modules\ndb\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#2.1.3: wanted {"os":"darwin","arch":"any"} (current:
{"os":"win32","arch":"x64"})
+ ndb#1.1.5
added 142 packages from 70 contributors and updated 1 package in 142.629s
When trying to this, one
$ node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp#5.0.5
gyp info using node#12.13.0 | win32 | x64
gyp info find Python using Python version 2.7.17 found at "C:\Python27\python.exe"
gyp info find VS using VS2019 (16.6.30204.135) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python27\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp
\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\monir\\Desktop\\WS-NODE\\NodeJS\\NATOURES\\build\\config.
gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp
\\addon.gypi',
gyp ginfo spawn args '-I',
gyp info spawn args 'C:\\Users\\monir\\AppData\\Local\\node-gyp\\Cache\\12.13.0\\include\
\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\monir\\AppData\\Local\\node-gyp\\Cache\\1
2.13.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\Program Files\\nodejs\\node_modules\\npm\\node_mo
dules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\monir\\\\AppData\\\\Local\\\\node-gyp-gyp
\\\\Cache\\\\12.13.0\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\Users\\monir\\Desktop\\WS-NODE\\NodeJS\\NATOURTOUR
ES',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'C:\\Users\\monir\\Desktop\\WS-NODE\\NodeJS\\NATOURES\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
yp: binding.gyp not found (cwd: C:\Users\monir\Desktop\WS-NODE\NodeJS\NATOURES) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\no
de_modules\node-gyp\lib\configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:210:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:272
:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_e" "C:\\Program Files\\nodejs\\node_
modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\monir\Desktop\WS-NODE\NodeJS\NATOURES
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
I have tried to resolve node gyp via powershell adminstrator its shows success but this error is shwoing always. How to resolve all this and i can run node debugger in my system?
Solved:
I have analysed this function from error log file,
async function downloadChromium(options, targetRevision) {
console.log(options); //Checking
const browserFetcher = puppeteer.createBrowserFetcher({ path: options.localDataDir });
const revision = targetRevision || require('puppeteer-core/package.json').puppeteer.chromium_revision;
const revisionInfo = browserFetcher.revisionInfo(revision);
console.log(revisionInfo); //checking
// Do nothing if the revision is already downloaded.
if (revisionInfo.local)
return revisionInfo;
// Override current environment proxy settings with npm configuration, if any.
try {
console.log(`Downloading Chromium r${revision}...`);
const newRevisionInfo = await browserFetcher.download(revisionInfo.revision);
console.log('Chromium downloaded to ' + newRevisionInfo.folderPath);
let localRevisions = await browserFetcher.localRevisions();
localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);
// Remove previous chromium revisions.
const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));
await Promise.all(cleanupOldVersions);
return newRevisionInfo;
} catch (error) {
console.error(`ERROR: Failed to download Chromium r${revision}!`);
console.error(error);
return null;
}
}
After Analyzing this function i consoled this,
$ ndb
{
bgcolor: '#242424',
channel: [ 'chromium' ],
paramsForReuse: {
data: 'eyJjd2QiOiJmaWxlOi8vL0M6L1VzZXJzL21vbmlyL0Rlc2t0b3AvV1MtTk9ERS9Ob2RlSlMvTkFUT1VSRVMiLCJhcmd2IjpbIkM6XFxQcm9ncmFtIEZpbGVzXFxub2RlanNcXG5vZGUuZXhlIiwiQzpcXFVzZXJzXFxtb25pclxcQXBwRGF0YVxcUm9hbWluZ1xcbnBtXFxub2RlX21vZHVsZXNcXG5kYlxcbmRiLmpzIl0sIm5vZGVFeGVjUGF0aCI6IkM6XFxQcm9ncmFtIEZpbGVzXFxub2RlanNcXG5vZGUuZXhlIn0='
},
localDataDir: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data'
}
{
revision: '624492',
executablePath: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data\\win64-624492\\chrome-win\\chrome.exe',
folderPath: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data\\win64-624492',
local: false,
url: 'https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/624492/chrome-win.zip'
}
From this console i browse this url https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/624492/chrome-win.zip from my browser and i noticed that this url is blocked from my country so i browse this directory form VPN and download the file then i extracted the file to C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data\\win64-624492 this directory, as the function returns false
if (revisionInfo.local)
return revisionInfo;
so i thought that is it possible to make this statement true? then find out the solution and make this statement true, so now its working perfectly,
{
bgcolor: '#242424',
channel: [ 'chromium' ],
paramsForReuse: {
data: 'eyJjd2QiOiJmaWxlOi8vL0M6L1VzZXJzL21vbmlyL0Rlc2t0b3AvV1MtTk9ERS9Ob2RlSlMvTkFUT1VSRVMiLCJhcmd2IjpbIkM6XFxQcm9ncmFtIEZpbGVzXFxub2RlanNcXG5vZGUuZXhlIiwiQzpcXFVzZXJzXFxtb25pclxcQXBwRGF0YVxcUm9hbWluZ1xcbnBtXFxub2RlX21vZHVsZXNcXG5kYlxcbmRiLmpzIl0sIm5vZGVFeGVjUGF0aCI6IkM6XFxQcm9ncmFtIEZpbGVzXFxub2RlanNcXG5vZGUuZXhlIn0='
},
localDataDir: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data'
}
{
revision: '624492',
executablePath: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data\\win64-624492\\chrome-win\\chrome.exe',
folderPath: 'C:\\Users\\monir\\AppData\\Roaming\\npm\\node_modules\\ndb\\node_modules\\carlo\\lib\\.local-data\\win64-624492',
local: true,
url: 'https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/624492/chrome-win.zip'
}
and finally after long time i am success to solve the problem!

symbol lookup error while starting a electron script using serialport

I am getting the following error:
/usr/share/nginx/html/arrowBank/node_modules/electron/dist/electron: /lib/x86_64-linux-gnu/libdbus-1.so.3: no version information available (required by /usr/share/nginx/html/arrowBank/node_modules/electron/dist/electron)
/usr/share/nginx/html/arrowBank/node_modules/electron/dist/electron: /lib/x86_64-linux-gnu/libdbus-1.so.3: no version information available (required by **strong text**/usr/share/nginx/html/arrowBank/node_modules/electron/dist/electron)
Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank"
selected /dev/ttyUSB1
/usr/share/nginx/html/arrowBank/node_modules/electron/dist/electron .: symbol lookup error: /usr/share/nginx/html/arrowBank/node_modules/#serialport/bindings/build/Release/bindings.node: undefined symbol: _ZN2v811HandleScope12CreateHandleEPNS_8internal10HeapObjectEPNS1_6ObjectE
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! arrowbank#1.0.0 start: `electron .`
npm ERR! spawn ENOENT`enter code here`
npm ERR!
npm ERR! Failed at the arrowbank#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ebuilders/.npm/_logs/2019-07-18T05_55_53_359Z-debug.log
Uninstall the serialport and reinstall those serialport but that issue not fixed. My npm version : 6.4.1, node version :10.14.0,serialport version :7.1.5
My code:
ipcMain.on('send-selectedPort',(event, arg) =>{
var selectedPort = arg;
var port = new serialport(selectedPort, {
baudRate: 9600,
autoOpen: false
});
if(port){
port.write('Hello', function(err, res) {
if (res) {
console.log("screen Res",res);
}
if (err) {
console.log('Error on write: ', err)
}
})
})

Firebase Cloud Function Send Notification Error

I'm trying to send a notification using Firebase Cloud Functions to all users whenever data is added to a certain collection within Firestore.
Here is my cloud function code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config.firebase);
exports.makeUppercase = functions.firestore.document('messages/{messageId}')
.onCreate((snap, context) => {
const value = snap.data().original;
console.log('notifying ' + value);
return Promise.all([value]).then(result => {
const value = result[0].data().value;
const payload = {
notification: {
title: "Added",
body: "Data Added"
}
};
admin.messaging().send(payload, false).then(result => {
console.log("Notification sent!");
});
});
});
When I'm trying to create this function using firebase deploy --only functions, I'm getting an error in console.
/Users/rachitgoyal/functions/index.js
35:40 error Each then() should return a value or throw promise/always-return
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rachitgoyal/.npm/_logs/2019-05-08T08_36_48_838Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
Additional logs from debug.log for reference:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli '--prefix',
1 verbose cli '/Users/rachitgoyal/functions',
1 verbose cli 'run',
1 verbose cli 'lint' ]
2 info using npm#6.4.1
3 info using node#v10.15.3
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions#~prelint: functions#
6 info lifecycle functions#~lint: functions#
7 verbose lifecycle functions#~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions#~lint: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/rachitgoyal/functions/node_modules/.bin:/Users/rachitgoyal/.npm-global/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle functions#~lint: CWD: /Users/rachitgoyal/functions
10 silly lifecycle functions#~lint: Args: [ '-c', 'eslint .' ]
11 silly lifecycle functions#~lint: Returned: code: 1 signal: null
12 info lifecycle functions#~lint: Failed to exec lint script
13 verbose stack Error: functions# lint: `eslint .`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:189:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:189:13)
13 verbose stack at maybeClose (internal/child_process.js:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid functions#
15 verbose cwd /Users/rachitgoyal
16 verbose Darwin 18.5.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/Users/rachitgoyal/functions" "run" "lint"
18 verbose node v10.15.3
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error functions# lint: `eslint .`
22 error Exit status 1
23 error Failed at the functions# lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
The funny thing here is that if I comment the below code in my index.js, the deployment works fine.
const payload = {
notification: {
title: "Added",
body: "Data Added"
}
};
admin.messaging().send(payload, false).then(result => {
console.log("Notification sent!");
});
So I'm assuming I'm doing something wrong with the initialization of the notification. Or I'm not returning the values to Promise properly. Any help here would be greatly appreciated.
Promise.all() and admin.messaging().send() both return a Promise, therefore you need to chain those promises.
However it is not clear why you do
const value = snap.data().original;
console.log('notifying ' + value);
return Promise.all([value])
.then(result => {
const value = result[0].data().value;
...
If you just want to use the value of value in your notification, you don't need to use Promise.all() at all and you should do as follows:
exports.makeUppercase = functions.firestore.document('messages/{messageId}')
.onCreate((snap, context) => {
const value = snap.data().original;
console.log('notifying ' + value);
const payload = {
notification: {
title: "Added",
body: value + "Data Added" //Here we use value
}
};
return admin.messaging().send(payload, false)
.then(result => { //Note that if you don't need the console.log you can get rid of this then()
console.log("Notification sent!");
return null;
});
});

Unable to deploy cloud functions

when I deployed my functions following error came up I tried everything but I cannot solve the problem
I am writing the function for push notification i think i write the code correctly but i am not sure its correct or not
This is the error which I receive on CMD
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\000\AppData\Roaming\npm-cache\_logs\2018-07-
20T15_42_18_516Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit
code1
This is the LOG File
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-
cli.js',
1 verbose cli '%RESOURCE_DIR%',
1 verbose cli 'run',
1 verbose cli 'lint' ]
2 info using npm#6.1.0
3 info using node#v10.4.1
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions#~prelint: functions#
6 info lifecycle functions#~lint: functions#
7 verbose lifecycle functions#~lint: unsafe-perm in lifecycle true
9 verbose lifecycle functions#~lint: CWD: C:\Users\000\fb-
functions\%RESOURCE_DIR%
10 silly lifecycle functions#~lint: Args: [ '/d /s /c', 'eslint .' ]
11 silly lifecycle functions#~lint: Returned: code: 1 signal: null
12 info lifecycle functions#~lint: Failed to exec lint script
13 verbose stack Error: functions# lint: `eslint .`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:304:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Program
Files\nodejs\node_modules\npm\node_modules\npm-
lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:961:16)
13 verbose stack at Process.ChildProcess._handle.onexit
(internal/child_process.js:248:5)
14 verbose pkgid functions#
15 verbose cwd C:\Users\000\fb-functions
16 verbose Windows_NT 10.0.10586
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program
Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--prefix"
"%RESOURCE_DIR%" "run" "lint"
18 verbose node v10.4.1
19 verbose npm v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error functions# lint: `eslint .`
22 error Exit status 1
23 error Failed at the functions# lint script.
23 error This is probably not a problem with npm. There is likely
additional logging output above.
24 verbose exit [ 1, true ]
This is the code which i wite in index.js
'use strict'
const functions = require('firebase-functions');
const admin = require ('firebase-admin');
admin.initializApp(functions.config().firebase);
exports.sendNotification=
functions.database.ref('/Notifications/${receiver_id}/{notification_id}')
.onWrite(event =>{
const receiver_id = event.params.receiver_id;
const notification_id = event.params.notification_id;
console.log('We have a Notifications to send to :',
receiver_id);
if (!event.data.val())
{
return console.log('A Notifications has been deleted from
the database', notification_id);
}
const deviceToken =
admin.database().ref(`/Users/${receiver_id}/device_token`)
.once('value');
return deviceToken.then(response =>
{
const token_id = result.val();
const payload =
{
notifications;
title: "Friend Request",
body: "You have a New Friend",
icon: "default"
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>{
console.log('This was the notification feature.');
});
};
});
});
What version of Cloud Functions are you using? If you are on 1.0 or later, then there are a couple of things to resolve in the code. For one, the guide indicates that Realtime Database .onWrite triggers pass two parameters: change and context. Also, the path shouldn't have a "$" in it. Also, the parameters object appears to encompassing the second half of all of the code. And in that payload it says "notifications;", but I'm not sure what that's supposed to be. Seems like it should match the payload shown in the guide. There may yet be other errors I didn't catch. If it were me, I'd probably try getting a simpler function to successfully deploy, and then add to it piece by piece.
exports.sendNotification = functions.database.ref('/Notifications/{receiver_id}/{notification_id}')
.onWrite((change, context) => {
const receiver_id = context.params.receiver_id;
const notification_id = context.params.notification_id;
console.log('We have a Notifications to send to :', receiver_id);
if (!change.after.val()) {
return console.log('A Notifications has been deleted from the database', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`)
.once('value');
return deviceToken.then(response => {
const token_id = result.val();
const payload = {
notification: {
title: 'Friend Request',
body: 'You have a New Friend',
icon: 'default'
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response => {
console.log('This was the notification feature.');
});
});
});

ELIFECYCLE error. How to fix it?

I am facing difficulty in deploying the notification function to the firebase.
I also used npm run clean but the error showed in it that-
npm ERR! missing script: clean
The index.js code is as follows-
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.pushNotification =
functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id;
const notification = event.params.notification;
console.log('We have a notification to send to : ', user_id);
if(event.data.val()){
return console.log('A Notification has been deleted feom the database :', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title : "Friend Request",
bosy : "You have received a new Friend Request",
icon : "default"
}
};
return admin.messaging().sendToDevice(/*Token ID*/, payload).then(response => {
console.log('This was the notification Feature');
});
});
});
The firebase deploy error in the Command Prompt is-
C:\Users\NIHIR\Desktop\MilApp\notificationFunction>firebase deploy
=== Deploying to 'milapp2-55dfb'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions
> eslint .
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
19:61 error Parsing error: Unterminated template
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-10T22_49_06_402Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
How to fix this error?
Using it in Windows 10.
Thanks in advance.
Even after correcting the mistake, I got the error again in deploying firebase as-
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
33:53 error Parsing error: Unexpected token ,
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-11T11_27_17_307Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
The error message is this:
19:61 error Parsing error: Unterminated template
It's referring to the fact that the template string on this line isn't terminated:
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');
You're missing the closing backtick for that reference string. It should be like this:
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken`).once('value');

Resources