node-7z and xml2json conflict - javascript

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
});

Related

#elastic/elasticsearch-mock Cannot destructure property `ConfigurationError` of 'undefined' or 'null'

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)

TypeError: module.exports is not a function

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;

TypeError: createDebug.load is not a function

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)
})

requiring same instance of module in another router nodejs

in server.js
const sql = require('mssql');
const getSqlInstance = () => {
return sql
}
module.exports = {
getSqlInstance
}
in database.js
const sql = require('../../server').getSqlInstance();
why does this throw require(...).getSqlInstance is not a function error? How do I resolve this?
folder structure
root
-- routes
--api
--database.js
--server.js
TypeError: require(...).getSqlInstance is not a function
at Object.<anonymous> (C:\Users\Jiho.Choi.ROOT_MILLIMAN\Desktop\BoosterADS\excelvcs\routes\api\database.js:4:37)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Jiho.Choi.ROOT_MILLIMAN\Desktop\BoosterADS\excelvcs\server.js:38:21)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3

Pass default parameter values in function react

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

Categories

Resources