I got this error after updating react-native and react
I think this is right syntax, but I don't know why this error is shown:
this.list = function(table, callback, wheredata = [],selection = '',extra = '') {
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object. (/Users/apcrat/Documents/redux/delfoo_React/api/model/catalog/cuisine_route.js:7:12)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
You need to compile your code with Babel.js to use Ecmascript 6 features or if you want to work on es5, you can do like this
Related
I am trying to mock #elastic/elasticsearch using the lib #elastic/elasticsearch-mock.
I have used the code as per the document and tried running but getting this
Code
const { Client } = require('#elastic/elasticsearch');
const Mock = require('#elastic/elasticsearch-mock');
const mock = new Mock();
const client = new Client({
node: 'http://localhost:9200',
Connection: mock.getConnection()
});
client.info(console.log)
But getting this error,
/home/app/node_modules/#elastic/elasticsearch-mock/index.js:18
ConfigurationError,
^
TypeError: Cannot destructure property `ConfigurationError` of 'undefined' or 'null'.
at Object.<anonymous> (/home/app/node_modules/#elastic/elasticsearch-mock/index.js:17:7)
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 Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/app/test/lib/es-helper-test.js:12:14)
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 Module._load (internal/modules/cjs/loader.js:724:14)
at Function.hookedLoader [as _load] (/home/app/node_modules/mockery/mockery.js:111:12)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /home/app/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/app/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/home/app/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/home/app/node_modules/mocha/bin/_mocha:403:18)
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)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11
Link: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html
Lib issue link : https://github.com/elastic/elasticsearch-js-mock/issues/15
Versions
"#elastic/elasticsearch": "7.13.0"
"#elastic/elasticsearch-mock": "^0.3.0"
You might need to add a resolver even just to console log the client.
From the very limited docs.
const { Client } = require('#elastic/elasticsearch')
const Mock = require('#elastic/elasticsearch-mock')
const mock = new Mock()
const client = new Client({
node: 'http://localhost:9200',
Connection: mock.getConnection()
})
// Add this resolver
mock.add({
method: 'GET',
path: '/'
}, () => {
return { status: 'ok' }
})
client.info(console.log)
From my understanding you will need to add every index, query, resolver, etc that you want to mock on the client since there is no database to query against - meaning you provide the data and tell the mock how you want it returned (also still learning this and the documentation for the mock library is quite brief)
My goal is to use the logger.js inside my app.js
I typed this from a tutorial but I have got different results than the tutorial.
-node-tutorial
--logger.js
--app.js
When I type node app.js in the console, I get this:
timbliefert#Tims-Air node-tutorial % node app.js
/Users/timbliefert/Developer/node-tutorial/logger.js:9
module.exports(log) = log;
^
TypeError: module.exports is not a function
at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/logger.js:9:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/app.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)```
module.exports is an object by default and you haven't reassigned it to a function so you're not able to invoke it with parenthesis like a function. You can add properties to module.exports exactly like how you'd add them to an object in JS through assignment.
module.exports.log = log;
I am facing the following error while trying to serve my project built using AdonisJs.
Error:
at setup (D:\NodeJsProjects\AdonisWallet\node_modules\knex\node_modules\debug\src\common.js:261:33)
at Object.<anonymous> (D:\NodeJsProjects\AdonisWallet\node_modules\knex\node_modules\debug\src\node.js:236:37)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (D:\NodeJsProjects\AdonisWallet\node_modules\knex\node_modules\debug\src\index.js:9:19)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
This problem is caused by the following line of code. In this code, AddonModel is a lucid Model provided by adonisjs
const ad= await AddonModule.findBy('name', addon_name)
I am not sure why is this happening. I have properly imported model using const AddonModule = use('App/Models/Addon')
Code seems like this
await files.forEach(async (file) => {
var addon_name=file
const ad= await AddonModule.findBy('name', addon_name)
})
I want to run some function inside javascript file via the console.
I'm using Node v12.14.1.
My case is as follows:
I have a testIt.js file as follows:
import {settings} from "./config";
const someMainFunction = (testParam) => {
console.log("This is init");
console.log("This PARAM", testParam);
otherFunction();
};
const otherFunction = () => {
console.log("This is other function")
};
export { someMainFunction }
I want to run someMainFunction via console.
I tried with
node -e 'require("./testIt").someMainFunction("Testing...")'
But it doesn't work.
I do not want to use any external libraries.
Any idea how to do that?
UPDATE
I get an error as follows:
import {settings} from "./frontend/config";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at [eval]:1:1
at Script.runInThisContext (vm.js:116:20)
at Object.runInThisContext (vm.js:306:38)
at Object.<anonymous> ([eval]-wrapper:9:26)
I've tried also with:
node --harmony testIt.js
But I get the same error.
UPDATE 2
When I try with
node --experimental-modules testIt.mjs
I get an error as follows:
(node:99449) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/esm/default_resolve.js:84
let url = moduleWrapResolve(specifier, parentURL);
^
Error: Cannot find module /Users/username/Projects/config imported from /Users/username/Projects/testIt.mjs
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:84:13)
at Loader.resolve (internal/modules/esm/loader.js:73:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:147:40)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:41:40)
at link (internal/modules/esm/module_job.js:40:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
UPDATE 3
import {settings} from "./frontend/config";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at [eval]:1:1
at Script.runInThisContext (vm.js:116:20)
at Object.runInThisContext (vm.js:306:38)
at Object.<anonymous> ([eval]-wrapper:9:26)
in node.js,
I have problem when import both packages (node-7z and xml2json),
I have some function that no one calls it ("dummy"),
import { extractFull } from 'node-7z'
const xml2json = require('xml2json');
function dummy(){
const myStream = extractFull('./zip/myfile.7z', './unzipped/')
}
and I get the following error
C:\projects\nodeTests\node_modules\joi\lib\types\object\index.js:445
source-map-support.js:445
Hoek.assert(isRegExp || pattern instanceof Any, 'pattern must be a regex or schema');
^
AssertionError [ERR_ASSERTION]: pattern must be a regex or schema
source-map-support.js:448
at internals.Object.pattern (C:\projects\nodeTests\node_modules\joi\lib\types\object\index.js:445:14)
at Object.internals.root (C:\projects\nodeTests\node_modules\joi\lib\index.js:432:34)
at Object.<anonymous> (C:\projects\nodeTests\node_modules\joi\lib\index.js:447:28)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\projects\nodeTests\node_modules\xml2json\lib\xml2json.js:3:11)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
*if I comment the code inside "dummy" function I dont get any error
*if I comment the line of require "xml2json" I dont get any error
why I have this problem and why how does the code in "dummy" function affect me if no one calls this function?
Thanks
https://github.com/quentinrossetti/node-7z according to this link you shoud pass an object with extractFull function for example
import Seven from 'node-7z'
const myStream = Seven.extractFull('./archive.7z', './output/dir/', {
$progress: true
});