an error occurred node js connect mongodb - javascript

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' ]
}

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!

Node.JS: Cannot find module './abort.js'

I'm using node.js v17.3.0 and im trying to upload my Discord bot to my raspberry pi. On my local PC it works, but on my raspi i get this error:
Anyone has a solution for that?
[Bot-Handler] Starting Bot...
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './abort.js'
Require stack:
- /home/excerz/node_modules/combined-stream/lib/combined_stream.js
- /home/excerz/node_modules/form-data/lib/form_data.js
- /home/excerz/node_modules/discord.js/src/rest/APIRequest.js
- /home/excerz/node_modules/discord.js/src/rest/RESTManager.js
- /home/excerz/node_modules/discord.js/src/client/BaseClient.js
- /home/excerz/node_modules/discord.js/src/index.js
- /home/excerz/main.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:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/excerz/node_modules/combined-stream/lib/combined_stream.js:1:13)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/excerz/node_modules/combined-stream/lib/combined_stream.js',
'/home/excerz/node_modules/form-data/lib/form_data.js',
'/home/excerz/node_modules/discord.js/src/rest/APIRequest.js',
'/home/excerz/node_modules/discord.js/src/rest/RESTManager.js',
'/home/excerz/node_modules/discord.js/src/client/BaseClient.js',
'/home/excerz/node_modules/discord.js/src/index.js',
'/home/excerz/main.js'
]
}
Node.js v17.3.0```

Keep getting this error Error: Cannot find module './config.json'

Here is the error that I get every time I try to execute the code and I can't find a solution so please help.
PS C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik> node .
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module './config.json'
Require stack:
- C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\commands\Test.js
- C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\commands\Test.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\boble\\OneDrive\\Desktop\\ScriptsNStuff\\karmik\\commands\\Test.js',
'C:\\Users\\boble\\OneDrive\\Desktop\\ScriptsNStuff\\karmik\\index.js'

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

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

Categories

Resources