Issue with rewire.js - Error: Cannot find module <path to rewired module> - javascript

So my directory structure looks like this:
and this is basically the cookie cutter use case for the rewire library right?
So my test module is very bare bones, just trying to rewire the module I want to test.
fetchTerms.test.js
import test from 'ava';
import rewire from 'rewire';
let fetchTerms = rewire('../src/fetchTerms.js');
let dateIsValid = fetchTerms.__get__("dateIsValid");
test("dateIsValid catches invalid dates", t => {
t.false(dateIsValid("999999"));
t.is("", "a");
});
fetchTerms.js
...
function dateIsValid(date) {
let month = parseInt(date.slice(4));
return 1 <= month && month <= 12;
}
...
export default <some other function>;
Unfortunately when I run with ava, I get this "cannot find module" error caused by the attempted rewire
> ava
✖ No tests found in target/test/fetchTerms.test.js
─
Uncaught exception in target/test/fetchTerms.test.js
Error: Cannot find module '../src/fetchTerms.js'
› internalRewire (node_modules/rewire/lib/rewire.js:23:25)
› rewire (node_modules/rewire/lib/index.js:11:12)
› file://target/test/fetchTerms.test.js:3:18
› ModuleJob.run (internal/modules/esm/module_job.js:138:23)
› Loader.import (internal/modules/esm/loader.js:178:24)
─
1 uncaught exception
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fetch_courses#1.0.0 test: `ava`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fetch_courses#1.0.0 test 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! /mnt/c/Users/********/.npm/_logs/2020-07-22T03_11_15_418Z-debug.log
Unless you can find anything wrong with the rewire path ../src/fetchTerms.js I don't know what could possibly make rewire not know how to find fetchTerms.js.
Any ideas?

Related

Yarn, node-gyp rebuild compile error, node_modules/fsevents: Command failed

I am using Yarn to handle the packages.
yarn install shows the error regardless of the package that I use but the install looked like it successfully finished and files are set under node-modules directly.(Somehow jquery-ui did not appear under node-modules)
I deleted yarn.lock and tried again, but in vain.
Can anyone help?
My environment is like this below:
whitebear$ yarn -v
1.10.1
whitebear$ node -v
v11.0.0
whitebear$ npm -v
6.4.1
package.json
{
"devDependencies": {
"#symfony/webpack-encore": "^0.20.0",
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"node-sass": "^4.9.4",
"popper.js": "^1.14.4",
"sass-loader": "^7.1.0",
"webpack-notifier": "^1.6.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production"
},
"dependencies": {
"encore": "^0.0.30-beta",
"jquery-ui": "^1.12.1",
"jquery.event.drag": "^2.2.2",
"slickgrid-es6": "^3.0.1"
}
}
log for yarn install
whitebearnoMacBook-puro:myinvestlist whitebear$ sudo yarn install
yarn install v1.10.1
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning " > sass-loader#7.1.0" has unmet peer dependency "webpack#^3.0.0 || ^4.0.0".
warning "runway#3.15.47-beta" is missing a bundled dependency "favicon.json". This should be reported to the package maintainer.
[4/4] 📃 Building fresh packages...
[1/4] ⠈ fsevents
[-/4] ⠈ waiting...
[3/4] ⠈ fsevents
warning Error running install script for optional dependency: "/Users/whitebear/CodingWorks/httproot/myinvestlist/node_modules/encore/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/whitebear/CodingWorks/httproot/myinvestlist/node_modules/encore/node_modules/fsevents
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp#3.8.0
gyp info using node#11.0.0 | darwin | x64
gyp info spawn /usr/bin/python
gyp info spawn args [ '/usr/local/Cellar/node/11.0.0/libexec/lib/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 'make',
gyp info spawn args '-I',
gyp info spawn args '/Users/whitebear/CodingWorks/httproot/myinvestlist/node_modules/encore/node_modules/fsevents/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/local/Cellar/node/11.0.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/whitebear/.node-gyp/11.0.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=/Users/whitebear/.node-gyp/11.0.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/local/Cellar/node/11.0.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/whitebear/.node-gyp/11.0.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/Users/whitebear/CodingWorks/httproot/myinvestlist/node_modules/encore/node_modules/fsevents',
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 'build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CXX(target) Release/obj.target/fse/fsevents.o
In file included from ../fsevents.cc:6:
../../nan/nan.h:190:32: warning: 'BooleanValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
|| optionsObj->Get(opt)->BooleanValue();
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8.h:2568:3: note: 'BooleanValue' has been explicitly marked deprecated here
V8_DEPRECATED(\"Use maybe version\", bool BooleanValue() const);
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
declarator __attribute__((deprecated(message)))
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:194:32: warning: 'BooleanValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
&& optionsObj->Get(opt)->BooleanValue();
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8.h:2568:3: note: 'BooleanValue' has been explicitly marked deprecated here
V8_DEPRECATED(\"Use maybe version\", bool BooleanValue() const);
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
declarator __attribute__((deprecated(message)))
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:213:31: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
? optionsObj->Get(opt)->Uint32Value()
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
V8_DEPRECATED(\"Use maybe version\", uint32_t Uint32Value() const);
^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
declarator __attribute__((deprecated(message)))
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:339:13: error: no member named 'New' in 'v8::String'
return _NAN_ERROR(v8::Exception::Error, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:343:5: error: no member named 'ThrowException' in namespace 'v8'
_NAN_THROW_ERROR(v8::Exception::Error, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:11: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ~~~~^
../../nan/nan.h:343:5: error: no member named 'New' in 'v8::String'
_NAN_THROW_ERROR(v8::Exception::Error, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:26: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ^~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:348:9: error: no type named 'ThrowException' in namespace 'v8'
v8::ThrowException(error);
~~~~^
../../nan/nan.h:355:65: error: no member named 'New' in 'v8::String'
v8::Local<v8::Value> err = v8::Exception::Error(v8::String::New(msg));
~~~~~~~~~~~~^
../../nan/nan.h:356:50: error: expected '(' for function-style cast or type construction
v8::Local<v8::Object> obj = err.As<v8::Object>();
~~~~~~~~~~^
../../nan/nan.h:356:52: error: expected expression
v8::Local<v8::Object> obj = err.As<v8::Object>();
^
../../nan/nan.h:357:65: error: too few arguments to function call, expected 2, have 1
obj->Set(v8::String::New(\"code\"), v8::Int32::New(errorNumber));
~~~~~~~~~~~~~~ ^
/Users/whitebear/.node-gyp/11.0.0/include/node/v8.h:3154:3: note: 'New' declared here
static Local<Integer> New(Isolate* isolate, int32_t value);
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:357:26: error: no member named 'New' in 'v8::String'
obj->Set(v8::String::New(\"code\"), v8::Int32::New(errorNumber));
~~~~~~~~~~~~^
../../nan/nan.h:369:12: error: no member named 'New' in 'v8::String'
return _NAN_ERROR(v8::Exception::TypeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:373:5: error: no member named 'ThrowException' in namespace 'v8'
_NAN_THROW_ERROR(v8::Exception::TypeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:11: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ~~~~^
../../nan/nan.h:373:5: error: no member named 'New' in 'v8::String'
_NAN_THROW_ERROR(v8::Exception::TypeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:26: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ^~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:377:12: error: no member named 'New' in 'v8::String'
return _NAN_ERROR(v8::Exception::RangeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:381:5: error: no member named 'ThrowException' in namespace 'v8'
_NAN_THROW_ERROR(v8::Exception::RangeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:11: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ~~~~^
../../nan/nan.h:381:5: error: no member named 'New' in 'v8::String'
_NAN_THROW_ERROR(v8::Exception::RangeError, errmsg);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:324:26: note: expanded from macro '_NAN_THROW_ERROR'
v8::ThrowException(_NAN_ERROR(fun, errmsg)); \\\n ^~~~~~~~~~~~~~~~~~~~~~~
../../nan/nan.h:319:50: note: expanded from macro '_NAN_ERROR'
# define _NAN_ERROR(fun, errmsg) fun(v8::String::New(errmsg))
~~~~~~~~~~~~^
../../nan/nan.h:406:13: error: no member named 'smalloc' in namespace 'node'
, node::smalloc::FreeCallback callback
~~~~~~^
../../nan/nan.h:141:71: note: expanded from macro 'NAN_INLINE'
# define NAN_INLINE(declarator) inline __attribute__((always_inline)) declarator
^~~~~~~~~~
../../nan/nan.h:416:12: error: no matching function for call to 'New'
return node::Buffer::New(data, size);
^~~~~~~~~~~~~~~~~
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:49:40: note: candidate function not viable: no known conversion from 'char *' to 'v8::Isolate *' for 1st argument
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:52:40: note: candidate function not viable: no known conversion from 'char *' to 'v8::Isolate *' for 1st argument
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:64:40: note: candidate function not viable: requires 3 arguments, but 2 were provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:57:40: note: candidate function not viable: requires 5 arguments, but 2 were provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:420:12: error: no matching function for call to 'New'
return node::Buffer::New(size);
^~~~~~~~~~~~~~~~~
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:49:40: note: candidate function not viable: requires 2 arguments, but 1 was provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:52:40: note: candidate function not viable: requires at least 2 arguments, but 1 was provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:64:40: note: candidate function not viable: requires 3 arguments, but 1 was provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
/Users/whitebear/.node-gyp/11.0.0/include/node/node_buffer.h:57:40: note: candidate function not viable: requires 5 arguments, but 1 was provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
^
In file included from ../fsevents.cc:6:
../../nan/nan.h:427:26: error: no member named 'Use' in namespace 'node::Buffer'
return node::Buffer::Use(data, size);
~~~~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
3 warnings and 20 errors generated.
make: *** [Release/obj.target/fse/fsevents.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/Cellar/node/11.0.0/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command \"/usr/local/Cellar/node/11.0.0/bin/node\" \"/usr/local/Cellar/node/11.0.0/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/whitebear/CodingWorks/httproot/myinvestlist/node_modules/encore/node_modules/fsevents
gyp ERR! node -v v11.0.0
✨ Done in 87.84s.
I just ran into something similar. deleting node_modules and removing yarn.lock fixed the problem for me.
sudo rm -r node_modules && rm yarn.lock && yarn install
Not sure if it was getting caught up on some conflicts.
yarn upgrade did the trick for me, see https://github.com/yarnpkg/yarn/issues/5962
Add this to your package.json file, then re-run yarn (or yarn install):
"resolutions": {
"**/**/fsevents": "^1.2.9"
}
source : https://github.com/yarnpkg/yarn/issues/5962#issuecomment-491934806
Do you have all the tools listed here for your OS? https://github.com/nodejs/node-gyp#installation
I downgraded the node version to v8.16.0. You could use n for this. It worked for me.
Make sure you remove previous versions before that.
brew uninstall node
Install downgraded version
brew install n
n 8.16.0
If it doesn't work though, try downgrading/upgrading your node versions.
downgrading to node 12 LTS version worked for me.
I used nvm for this.

TypeError: Super expression must either be null or a function

I'm very new to unit Testing in vue js. I just went through this website to learn unit testing "https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack". while I'm practicing the examples in "mocha-webpack" I got this Error
WEBPACK Failed to compile with 1 error(s)
Error in ./src/Counter.vue
TypeError: Super expression must either be null or a function
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32893:5
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32913:4
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mdbvue#4.2.0 test: `mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mdbvue#4.2.0 test 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! /root/.npm/_logs/2018-09-06T10_28_47_073Z-debug.log
Can anyone tell me how to solve this error. This is my Counter.vue file
<template>
<div>
<div>
{{ count }}
<button #click="increment">Increment</button>
</div>
</div>
</template>
<script>
export default {
data () {
return {
count: 0
}
},
methods: {
increment () {
this.count++;
}
}
};
</script>
Here is my Counter.spec.js File
import { shallowMount } from '#vue/test-utils'
import Counter from '../src/docs/Counter.vue'
describe('Counter.vue', () => {
it('increments count when button is clicked', () => {
const wrapper = shallowMount(Counter)
wrapper.find('button').trigger('click')
expect(wrapper.find('div').text()).toMatch('1')
})
})
I've looked at the issue linked above.
I have --require test/setup.js in the test script. Here's how it looks like:
require('jsdom-global')();
window.Date = Date;
It solved the problem. Try it out!
It is a problem related with version 1.14.1 of prettier, that is a NPM package used in your scenario.
Indeed, looking at their GitHub repo the issue is reported. At the moment there is a possible workaround: basically, it is to comment out line 32893 of prettier/index.js.
In your environment you can find the file here: /opt/htdocs/guru/unitTest_prct/node_modules/.

npm start returning an error

I am having difficulty with an error when I run 'npm start' on my mean.js application. I will paste both the terminal output and the code from the file with the error.
Terminal:
/Users/developer/dev-projects/Central-Repo/node_modules/rcloader/index.js:39
if (err) throw err;
^
Error: ENOENT: no such file or directory, open '.csslintrc'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! meanjs#0.6.0 start: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the meanjs#0.6.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! /Users/developer/.npm/_logs/2018-07-24T09_18_22_923Z-debug.log
Index.js: (error in 10th line of code)
var defaultFileGiven = (config.defaultFile !== undefined);
if (defaultFileGiven) {
if (finder.canLoadSync) {
assign(config, finder.get(config.defaultFile));
} else {
// push callbacks here that need to wait for config to load
configPending = [];
// force the async loader
finder.get(config.defaultFile, function (err, defaults) {
if (err) throw err;
assign(config, defaults);
// clear the configPending queue
var cbs = configPending;
configPending = null;
cbs.forEach(function (cb) { cb(); });
});
}
}
It seems .csslintrc file is not available in your project folder. You can re download this from the master branch and try again.

Error with deploy function to Firebase

I'm trying to deploy function to Firebase
$ npm install firebase-tools
$ login firebase
$ firebase init functions
then $firebase deploy --only functions or $firebase deploy
package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"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": {
"firebase-admin": "~5.12.1",
"firebase-functions": "^1.0.3"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
firebase.json:
{
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
}
}
edited with $RESOURCE_DIR as %RESOURCE_DIR% to avoid:
Error: functions predeploy error: Command terminated with non-zero
exit code4294963238
my function index.js:
const functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var wrotedata;
exports.Pushtrigger = functions.database.ref('/messages/{messageId}').onWrite((event) => {
wrotedata = event.data.val();
admin.database().ref('/pushtokens').orderByChild('uid').once('value').then((alltokens) => {
var rawtokens = alltokens.val();
var tokens = [];
this.processtokens(rawtokens).then((processedtokens) => {
for (var token in processedtokens) {
tokens.push(token.devtoken);
}
var payload = {
"notification": {
"title": "Notification title",
"body": "Notification body",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"message": "value1",
"sendername": "value2"
}
}
return admin.messaging().sendToDevice(tokens, payload).then((response) => {
console.log('Push notifications');
}).catch((err) => {
console.log(err);
})
})
})
})
function processtokens(rawtokens) {
var promise = new Promise((resolve, reject) => {
var processedtokens = []
for (token in rawtokens) {
processedtokens.push(rawtokens[token]);
}
resolve(processdatatokens);
})
return promise;
}
I've tried:
npm install firebase-admin#latest firebase-functions#latest
npm install -g git://github.com/firebase/firebase-tools#master
but I got:
Error: functions predeploy error: Command terminated with non-zero
exit code1
2018-07-12T23_38_09_788Z-debug:
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 '--prefix',
1 verbose cli 'C:\\Users\\User\\Desktop\\pushcloud\\functions',
1 verbose cli 'run',
1 verbose cli 'lint' ]
2 info using npm#5.6.0
3 info using node#v8.9.4
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: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\User\Desktop\pushcloud\functions\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Embarcadero\Studio\16.0\bin;C:\Users\Public\Documents\Embarcadero\Studio\16.0\Bpl;C:\Program Files (x86)\Embarcadero\Studio\16.0\bin64;C:\Users\Public\Documents\Embarcadero\Studio\16.0\Bpl\Win64;C:\Inprise\vbroker\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Python27;C:\Python27\Scripts\;C:\Users\User\AppData\Local\Programs\Python\Python35-32;C:\Users\User\AppData\Local\Programs\Python\Python35-32\Scripts;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Emgu\emgucv-windesktop 3.1.0.2282\bin\x86;C:\Program Files (x86)\Skype\Phone\;C:\php;C:\Apache2;C:\Apache2\bin;C:\Program Files\dotnet\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Java\jdk1.8.0_151\bin;C:\Users\User\AppData\Local\Android\Sdk\platform-tools;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Git\usr\bin;C:\Go\bin;C:\Program Files (x86)\Java\jre1.8.0_101\bin;C:\Users\User\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\User\AppData\Local\Programs\Python\Python35-32\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\User\AppData\Roaming\npm;C:\Users\User\go\bin
9 verbose lifecycle functions#~lint: CWD: C:\Users\User\Desktop\pushcloud\functions
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:285:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
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 emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:925:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid functions#
15 verbose cwd C:\Users\User\Desktop\pushcloud
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--prefix" "C:\\Users\\User\\Desktop\\pushcloud\\functions" "run" "lint"
18 verbose node v8.9.4
19 verbose npm v5.6.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 ]
it looks like something wrong with code, because deploy of default Hello from Firebase! is successful
edit:
In case of edit in firebase.json form \"%RESOURCE_DIR%\" to "%RESOURCE_DIR%" error is
Error: There was an error loading firebase.json: Unexpected token '%'
"npm --prefix "%RESOURCE_DIR%" run lint"
If I remove line from firebase.json and run npm --prefix "%RESOURCE_DIR%" run lint in terminal:
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\User\Desktop\pushcloud\%RESOURCE_DIR%\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Roaming\npm-cache\_logs\2018-07-13T11_33_25_593Z-debug.log
but directory folder exist as %RESOURCE_DIR% with folder etc, when package.json located in functions directory. If I relocate it to %RESOURCE_DIR%:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
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 WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Roaming\npm-cache\_logs\2018-07-13T11_50_15_739Z-debug.log
and with $ firebase deploy --only functions:
C:\Users\User\Desktop\pushcloud\functions\index.js
9:5 error Expected catch() or return promise/catch-or-return
9:80 error Each then() should return a value or throw promise/always-return
12:9 error Expected catch() or return promise/catch-or-return
12:9 warning Avoid nesting promises promise/no-nesting
33:24 warning Avoid nesting promises promise/no-nesting
33:24 warning Avoid nesting promises promise/no-nesting
33:77 error Each then() should return a value or throw promise/always-return
✖ 7 problems (4 errors, 3 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\User\AppData\Roaming\npm-cache\_logs\2018-07-13T11_51_50_784Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
Your predeploy flag npm --prefix \"%RESOURCE_DIR%\" run lint is causing your issues.
If you run npm --prefix "%RESOURCE_DIR%" run lint in your terminal, does it run correctly without error?
If you remove that line from your firebase.json then it should deploy without issue.
EDIT
Check the error message you're receiving, it has the answer for you. Your code linter is failing, and you'll need to fix those errors before you can deploy.
9:5 error Expected catch() or return promise/catch-or-return
9:80 error Each then() should return a value or throw promise/always-return
12:9 error Expected catch() or return promise/catch-or-return
12:9 warning Avoid nesting promises promise/no-nesting
33:24 warning Avoid nesting promises promise/no-nesting
33:24 warning Avoid nesting promises promise/no-nesting
33:77 error Each then() should return a value or throw promise/always-return
I've taken a quick look at your code, and I think I've cleaned it up. Additionally you didn't need to make processtokens a promise, it's a synchronous functions.
const functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var wrotedata;
exports.Pushtrigger = functions.database.ref('/messages/{messageId}').onWrite((event) => {
wrotedata = event.data.val();
return admin.database().ref('/pushtokens')
.orderByChild('uid')
.once('value')
.then((alltokens) => {
var rawtokens = alltokens.val();
var tokens = [];
var processedtokens = this.processtokens(rawtokens);
for (var token in processedtokens) {
tokens.push(token.devtoken);
}
var payload = {
"notification": {
"title": "Notification title",
"body": "Notification body",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"message": "value1",
"sendername": "value2"
}
};
return admin.messaging().sendToDevice(tokens, payload).then((response) => {
console.log('Push notifications');
}).catch((err) => {
console.log(err);
})
})
})
function processtokens(rawtokens) {
var processedtokens = []
for (token in rawtokens) {
processedtokens.push(rawtokens[token]);
}
return processdatatokens;
}

Cannot read source folder attempting to make any action

When attempting to run my nightwatch project with npm run project_one, I get this response.
There was an error while starting the test runner:
Error: Cannot read source folder: /Users/BenyJo/examples/tests
at /Users/BenyJo/node_modules/nightwatch/lib/runner/run.js:203:21
at /Users/BenyJo/node_modules/nightwatch/lib/runner/walk.js:97:18
at FSReqWrap.oncomplete (fs.js:153:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package#1.0.0 project_one: `nightwatch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the package#1.0.0 project_one script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Whenever I use any nightwatch command using npm, I get the same error, my Nightwatch config is as follows:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"selenium" : {
"start_process" : true,
"server_path" : "./bin/selenium_v360.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./bin/chromedriver"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
I've noticed that in that error, there is no file called, there should be a nightwatch folder in there. /Users/BenyJo/examples/tests
['nightwatch', '--', '--group', "$testSuite", '--env', "$projectEnv"].
I've resolved the issue "Error: Cannot read source folder: /"
Executing the command in this two ways:
nightwatch -- --group testSuite --env nameEnv
npm run test -- --group testSuite --env nameEnv
nightwatch -- --test testsFile/testSuite --env default
npm run test -- --test testsFile/testSuite --env default
Keep in mind the double argument lines: "-- --group".
It resolved runner.js in this way to Nightwatch execution
you can Replace the group or file test in your project and review the test Setting in nighwatch.json to resolve the parameter --env or -e
Had the same problem, there was a typo in my config file name. It must be named "nightwatch.json" (mine was named "nightwatch.js").

Categories