Cannot find module - node.js

Could somebody help. I have such project structure and my node app complaints about this generated file(error_pb.js). In index.js with 'google-protobuf' I do not have such problem. Is there ideas how to solve it?
my_prj\src\server> node .
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'google-protobuf'
Require stack:
- \my_prj\gen\js\proto\error_pb.js
- \my_prj\src\server\modules\requestHandlers\topicHandler.js
- \my_prj\src\server\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (\my_prj\gen\js\proto\error_pb.js:14:12)
thanks in advance.

Related

Cannot find module 'fs/promises' using JHipster

I'm using nvm and I'm having this error when using jhipster. It was previously working when I'm not using nvm.
jhipster version: v7.9.3
node: v12.22.12
npm: 6.14.16
ERROR! Cannot find module 'fs/promises'
Require stack:
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/generators/bootstrap/index.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/util/esm.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/store.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/environment-builder.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/program.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/cli.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/jhipster.js
Error: Cannot find module 'fs/promises'
Require stack:
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/generators/bootstrap/index.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/util/esm.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/store.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/environment-builder.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/program.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/cli.js
- /Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/jhipster.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/generators/bootstrap/index.js:29:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/generators/bootstrap/index.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/util/esm.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/store.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/environment-builder.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/program.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/cli.js',
'/Users/xxxx/.nvm/versions/node/v12.22.12/lib/node_modules/generator-jhipster/cli/jhipster.js'
]
}
Anyone have any idea why is the error and how to fix it? Thanks
I was able to make it work by using node 16.14.2

Running Ghost in Github - Error: Cannot find module '/home/runner/work/website/website/package.json'

I'm trying to build a website using Ghost and followed the tutorial to connect it with GitHub exactly. When I run the code in the .github/workflows/main.yml file I get the error:
Run TryGhost/action-deploy-theme#v1.4.1
Error: Cannot find module '/home/runner/work/website/website/package.json'
Require stack:
- /home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at main (/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:1560:62)
at Object.104 (/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:1578:2)
at __webpack_require__ (/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:24:31)
at startup (/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:43:19)
at /home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:47:18
at Object.<anonymous> (/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js:50:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/runner/work/_actions/TryGhost/action-deploy-theme/v1.4.1/dist/index.js'
]
}
If anyone knows how to fix this problem I'd appreciate you letting me know :)

When starting a discord bot i get this error

When starting my discord bot that I created a couple years ago I'm getting this error, I've no clue on whats causing it. I have done the uninstall of the node_modules and reinstalling etc but I'm not sure what the error could be caused by, any ideas?
Error:
PS C:\Users\Admin\Documents\Bot> node index.js
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module 'better-sqlite3'
Require stack:
- C:\Users\Admin\Documents\Bot\node_modules\enmap\src\index.js
- C:\Users\Admin\Documents\Bot\node_modules\enmap\index.js
- C:\Users\Admin\Documents\Bot\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at new Enmap (C:\Users\Admin\Documents\Bot\node_modules\enmap\src\index.js:110:24)
at Object.<anonymous> (C:\Users\Admin\Documents\Bot\index.js:5:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Admin\\Documents\\Bot\\node_modules\\enmap\\src\\index.js',
'C:\\Users\\Admin\\Documents\\Bot\\node_modules\\enmap\\index.js',
'C:\\Users\\Admin\\Documents\\Bot\\index.js'
]
}
First make sure better-sqlite3 is installed
npm i better-sqlite3
then that it has been defined
const better-sqlite3 = require('better-sqlite3')

Cannot find module 'install-npm-version'

I'm developing this project with TypeScript: https://github.com/scott-lin/install-npm-version
When trying to consume the package within another project, I'm getting Cannot find module 'install-npm-version' error.
Repro Steps
npm install install-npm-version#1.0.2
Create repro.js file with const inv = require('install-npm-version'); as the content
Invoke the repro with node .\repro.js
Error
> node .\repro.js
module.js:545
throw err;
^
Error: Cannot find module 'install-npm-version'
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\scottlin.REDMOND\Desktop\test\repro.js:1:75)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
PS C:\Users\scottlin.REDMOND\Desktop\test>
The main property in the package.json file is used to find the module when using as an in-code Node module. Yours starts with a slash, implying the root directory. This is incorrect, which is why your code is failing.
To fix:
Change
"main": "/lib/Install.js",
to
"main": "lib/Install.js",

Cannot find module in Nodejs

module.js:340
throw err;
^
Error: Cannot find module './models/todo'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Basel\Desktop\Todo List\routes\api.js:1:74)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
C:\Users\Basel\Desktop\Todo List>
Why this application won't start up? I've already tried a global npm install.
In ./models/todo, the period indicates that node will look in the same folder that api.js is in, which would look for \Todo List\routes\models\todo.js. This does not start from the root of the application. To require this, you'll need to us two periods to jump up a level, and specify the app path as well:
var todo = require('../app/models/todo');
maybe you did not set the system value : NODE_PATH; it should point to your global module location;
in Linux: export NODE_PATH=/usr/local/lib/node_modules/ works good for me;
in my case, the file name i had given in my require statement was wrong. I had my models file named posts.js and i was using require('./models/post'). It worked after i changed it to require ('.models/posts')

Resources