requiring same instance of module in another router nodejs - javascript

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

Related

Can't find module "semver" on node.js / code: 'MODULE_NOT_FOUND',

I'm having trouble running a project. He always falls into this error. What can it be?
node:internal/modules/cjs/loader:956
const err = new Error(message);
^
Error: Cannot find module 'semver'
Require stack:
- /usr/share/nodejs/npm/lib/utils/unsupported.js
- /usr/share/nodejs/npm/lib/cli.js
- /usr/share/nodejs/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/usr/share/nodejs/npm/lib/utils/unsupported.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/nodejs/npm/lib/utils/unsupported.js',
'/usr/share/nodejs/npm/lib/cli.js',
'/usr/share/nodejs/npm/bin/npm-cli.js'
]
}
I have already reinstalled and installed npm several times. I cleared cache and everything and nothing!

an error occurred node js connect mongodb

node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './logic/products'
Require stack:
E:\wz\route\products.js
E:\wz\app.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (E:\wz\route\products.js:3:54)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'E:\wz\route\products.js', 'E:\wz\app.js' ]
}
E:\wz> node app.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './logic/products'
Require stack:
E:\wz\route\products.js
E:\wz\app.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (E:\wz\route\products.js:3:21)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'E:\wz\route\products.js', 'E:\wz\app.js' ]
}

Solution to 'Uncaught error' - when trying to use Vue JS with Laravel?

I am trying to create my first Vue component to couple with my laravel mvc application. It's simply a component to use in my 'welcome.blade.php' file.
However, I am getting the following javascript error message in my console, when trying to view the page, and a blank screen:
app.js:96 Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
C:\wamp64\www\client_transactions\node_modules\schema-utils\dist\util\hints.js:16
const currentSchema = { ...schema
^^^
SyntaxError: Unexpected token ...
at NativeCompileCache._moduleCompile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:242:18)
at Module._compile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:186:36)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\wamp64\www\client_transactions\node_modules\schema-utils\dist\ValidationError.js:11:5)
at Module._compile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\wamp64\www\client_transactions\node_modules\schema-utils\dist\validate.js:14:47)
at Module._compile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\wamp64\www\client_transactions\node_modules\schema-utils\dist\index.js:3:18)
at Module._compile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\wamp64\www\client_transactions\node_modules\babel-loader\lib\index.js:43:25)
at Module._compile (C:\wamp64\www\client_transactions\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at Object../resources/js/app.js (http://127.0.0.1:8000/js/app.js:96:7)
at __webpack_require__ (http://127.0.0.1:8000/js/app.js:20:30)
at Object.0 (http://127.0.0.1:8000/js/app.js:118:1)
at __webpack_require__ (http://127.0.0.1:8000/js/app.js:20:30)
at http://127.0.0.1:8000/js/app.js:84:18
at http://127.0.0.1:8000/js/app.js:87:10
This happens after completing the following steps to install Vue:
Navigate to laravel project root and run 'npm install'.
-Creating the following template:
<template>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
Welcome to Vue.js on Laravel
</div>
<div class="links">
View Laravel Docs
View Vue Docs
Watch Videos
</div>
</div>
</div>
</template>
<script>
export default {}
</script>
Updating my resources\js\app.js file to include the following:
require('./bootstrap');
window.Vue = require('vue');
Vue.component('welcome', require('./components/Welcome.vue'));
const app = new Vue({
el: '#app'
});
Placing the component inside of my resources/views/welcome.blade.php file:
<title>Laravel</title>
[...]
Adding a welcome route in laravel:
Route::get('/welcome', ['as' => 'welcome.index', 'uses' => 'home_controller#welcome']);
If anyone was able to suggest a step that I might be missing, that would be absolutely super.

node-7z and xml2json conflict

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

What is the right regex pattern for ignore in #babel/register

I am running mocha on some React components that contain openlayers, the new update ol modules are all written only in ES6 and they have to be transpiled before being passed to mocha for testing.
I am using #babel/register and I am requiring a babel-register.js file in which I require #babel/register and input all the options and presets/plugins. I does not transpile and I get the error you will see down below. All I would like is requiring only the node_modules/ol and recursively all files and subfolders to transpile is the regex correct? Is there anything else wrong? My babel-register.js is as follows:
require("#babel/polyfill");
require("#babel/register")({
ignore: [
// When a file path matches this regex then it is **not** compiled
'node_modules/(?!(ol)/)'
],
presets : ["react-app", "#babel/preset-env"],
plugins : [
"#babel/plugin-transform-modules-commonjs",
"inline-react-svg",
"#babel/plugin-syntax-dynamic-import",
"#babel/plugin-transform-runtime"
],
//root: __dirname,
extensions: [".es6", ".es", ".jsx", ".js", ".mjs"],
// Setting this to false will disable the cache.
cache: false,
});
Below is the error message I get from transiplation (I am not sure is because of regex):
/home/Development/test-openlayers/node_modules/#babel/runtime/helpers/typeof.js:8
if (typeof Symbol === "function" && (0, _typeof4.default)(Symbol.iterator) === "symbol") {
^
TypeError: (0 , _typeof4.default) is not a function
at _typeof2 (/home/alessandro/Development/test-openlayers/node_modules/#babel/runtime/helpers/typeof.js:1:62)
at _typeof2 (/home/alessandro/Development/test-openlayers/node_modules/#babel/runtime/helpers/typeof.js:4:39)
at Object.<anonymous> (/home/alessandro/Development/test-openlayers/node_modules/lodash.sortby/index.js:95:18)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/whatwg-url/lib/URLSearchParams-impl.js:2:22)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/whatwg-url/lib/URLSearchParams.js:432:14)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/whatwg-url/lib/URL-impl.js:4:25)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/whatwg-url/lib/URL.js:335:14)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/whatwg-url/lib/public-api.js:3:15)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/node_modules/jsdom/lib/api.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.require (/home/alessandro/Development/test-openlayers/setup.js:1:19)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module._compile (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (/home/alessandro/Development/test-openlayers/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at requires.forEach.mod (/home/alessandro/Development/test-openlayers/node_modules/mocha/bin/_mocha:511:3)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/alessandro/Development/test-openlayers/node_modules/mocha/bin/_mocha:510:10)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
So, thanks to #Thomas Skubicki, the regex slashes had to be escaped, two more slashes had to be put at the beginning and end of the reg expression and single quotes had to be removed, this is the correct working version of the babel-register.js file.
require("#babel/polyfill");
require("#babel/register")({
// Array of ignore conditions, either a regex or a function. (Optional)
ignore: [
// When a file path matches this regex then it is **not** compiled
/node_modules\/(?!(ol)\/)/
// The file's path is also passed to any ignore functions. It will
// **not** be compiled if `true` is returned.
//function(filepath) {
//return filepath !== "/path/to/es6-file.js";
//},
],
presets : ["react-app"],
plugins : [
"#babel/plugin-transform-modules-commonjs",
"inline-react-svg",
],
//root: __dirname,
// Optional only regex - if any filenames **don't** match this regex then they
// aren't compiled
//only: /my_es6_folder/,
// Setting this will remove the currently hooked extensions of `.es6`, `.es`, `.jsx`, `.mjs`
// and .js so you'll have to add them back if you want them to be used again.
extensions: [".es6", ".es", ".jsx", ".js", ".mjs"],
// Setting this to false will disable the cache.
cache: false,
});
Those forward slashes in that regex may need to be escaped
'node_modules\/(?!(ol)\/)'
That regex throws errors in regex101.com

Categories

Resources