Cannot find Realm module "(...)node_modules\Realm\build\Release\realm.node" - node.js

I'm trying to create node server using Realm. I have installed Realm like the docs say:
npm install realm. The module is visible in node_modules folder and package.json.
I try to import Realm like the docs say too:
const Realm = require("realm");
But this import throws an error (it's in my language, so translation of the error message might be not word-to-word):
Error: cannot find module:
\\?\D:\GIT\nuxt-test\node_modules\realm\build\Release\realm.node
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at bindings (D:\GIT\nuxt-test\node_modules\bindings\bindings.js:112:48)
at getRealmConstructor (D:\GIT\nuxt-test\node_modules\realm\lib\index.js:37:43)
at Object.<anonymous> (D:\GIT\nuxt-test\node_modules\realm\lib\index.js:62:26)
at Module._compile (internal/modules/cjs/loader.js:701:30)
Additional info:
OS - Windows 7
Node version: 16.4 (upgraded from 10.15.3 trying to solve this)
What might be wrong with my import?
EDIT:
I have noticed that on installation of Realm npm throws some warnings:
realm#10.5.0 requires a peer of react-native#>=0.60 but none is installed.
deprecated-react-native-listview#0.0.6 requires a peer of react#* but none is installed.
which is surprising as I'm not using react-native SDK, but the node one.
I tried to install realm-web package and it seems to function properly (!) even though I run it from node. But I don't know if this is an acceptable solution as docs say the realm-web package is not intended for node.

Related

Node "Error: Cannot find module 'node:process'" when using global fastify-cli (mac)

I'm setting up a new mac dev machine, and have gotten node, npm, and nvm installed. All seems fine within a single project directory. However, when trying to install and use fastify-cli, I'm receiving an error:
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
]
}
Steps to reproduce:
$ npm install --global fastify-cli (succeeds)
$ fastify generate myproject (also produces above error)
$ fastify (also produces above error)
This likely doesn't have much to do with fastify. It seems to me that the global package is not finding Node for some reason, but I may be wrong.
I'm using zshell
I've got xcode installed
I've upgraded the version of node i'm using
I'm able to start a fastify app from the app directory directly/without using the generator
Any thoughts?
I fixed the error following the answer in this GitHub issue reply
node internal syntax (e.g.: node:<core_module_name>) is not supported by Node.js 14.16.0
The CLI needs node version >= 14.19
Steps:
Upgrade node using nvm to 14.9.0 (the last lts in 14.x).
Set default version 14.9.0 or above.
you need to run
npm i #types/node
I solved it by switching the current user to a root user.
If you are using a Mac, try to switch to a root user account and do the same thing again.
I assigned my previous account as 'administrator' under system preferences, but this won't solve the issue. The problem was perfectly solved when I switched to my primary account.
Hope this could help!

Error: Module version mismatch - without removing node_modules

When trying to start up my application using node app.js I'm getting this error:
lucas#XYZ:~/app/lucas$ node app.js
module.js:583
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 48, got 57.
at Error (native)
at Object.Module._extensions..node (module.js:583:18)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/lucas/app/lucas/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
When I type in node -v I get v6.5.0
As this website shows, this corresponds to version 48, so where the 57 is coming from?
I know the default solution is deleting node_modules but I'd like to understand what's going on here and try to avoid that, and any other similar approaches that involve reinstalling all modules etc. Question is more about understanding the actual problem.
EDIT: If you're curious whats in that bindings.js file this is all that's inside:
'use strict';
module.exports = require('../build/Release/canvas.node');
Simply put Node 6.x is trying to open a native module built for Node 8.x.
Based on the traceback, it's the canvas module – you've somehow ended up with a newer native module for canvas in your node_modules than the Node you're running with. (One way this can happen is by using nvm, n or other node version manager.)
You don't necessarily have to nuke all of node_modules to fix this (though it doesn't hurt, and if you have a project that doesn't survive nuking node_modules, that's a problem in itself) – you could try renaming node_modules/canvas to node_modules/canvas.backup or something and running npm install (or yarn install) again (with the correct Node version active) and it should download/recompile the native module for canvas as it's reinstalling the now "missing" canvas.

I am getting an error when i run my node.js app ( also using rabbit )

Error: Cannot find module 'amqplib/callback_api'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
at Function.Module._load (internal/modules/cjs/loader.js:475:25)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)
at Object.<anonymous> (C:\Users\hello\Downloads\Private-Chat-App-Socket.io-
master\Private-Chat-App-Socket.io-master\app.js:3:9)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
I have tried to solve the error by installing amqp using npm but it does not work and i have also searched for solutions on the internet but no luck.
Pic of the error
I just noticed you're declaring amqp twice. In line 3 and 6:
var amqp = require('amqplip/callback_api'),
So I will suggest you check your code and choose the one you'll wanna use.
That aside, I think what you're trying to use is amqplib and not amqp
To resolve your problem, I will suggest you delete the node_modules dir completely, then run npm install, after which you run these:
npm install --save amqplib
This should solve your problem.

A module does not compile in a newer node.js version, any workarounds?

my open-source project depends on a lemmatization module —
https://github.com/grachev/node-lemmer
— which needs to be compiled before it can run.
After updating to a newer version of node.js I can't run this module, because it needs to be re-compiled. Usually this was done when I simply did npm install node-lemmer however it is now not available in npm and I don't know how to compile it under that new node version and why I have to do it at all...
I tried running npm rebuild but it does not recompile – too many errors. The issues folder of that project on GitHub has the issue up already but there's no fix for it...
What could I do about it? Why do I need to recompile this module when I install a new version of node? Is there a workaround? Could I "trick" node or that module so it doesn't need to recompile? Or maybe it's possible to compile it manually?
...
Some mode details:
I used to run my project on node 0.8.3 vesion and then switched to the new 8.8.0 version. Now when I try to run my project under the new node version it doesn't start giving the following error:
module.js:641
return process.dlopen(module, path._makeLong(filename));
^
Error: Module did not self-register.
at Object.Module._extensions..node (module.js:641:18)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:556:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
(/path-to-my-project/node_modules/node-lemmer/lib/node-lemmer.js:1:82)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
which is an error I've seen before because my module could not be compiled.
my project is https://github.com/noduslabs/infranodus in case it helps to see the source code.

Nodejs: TypeError: Object #<Object> has no method 'endianness'

I try to run server: node app.js on Ubuntu 14.04 LTS then get this error:
/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/topologies/shared.js:18
var nodejsversion = f('Node.js %s, %s', process.version, os.endianness());
^
TypeError: Object #<Object> has no method 'endianness'
at Object.<anonymous> (/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/topologies/shared.js:18:61)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/connection/pool.js:11:12)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
I have no idea what's wrong with this. I use Nodejs v6.9 and Mongodb v3.2.11, it should have module os that content 'endianness'?
The issue is that an older version of node is being used to run the script(s) (pre-v0.10 in this case). os.endianness() was added in node v0.10.0 (technically v0.9.x).
The reason for separate node and nodejs binaries on Linux is that some distributions (namely Debian-based) do that to avoid a conflict in package names. Before node.js, the 'node' package name was already being used by an amateur radio package, so when node.js became officially packaged by Debian they chose a different name ('nodejs') rather than replace the existing 'node' package. To also confuse things further, both packages use the same binary names, so that also had to be changed to avoid any potential confusion. This does present some problems though for shebangs that assume the node binary name.
Since most developers do not use the 'node' amateur radio package, one popular solution to the whole node/nodejs naming issue is to simply use a third-party repository (such as NodeSource's) that not only provides the latest versions of node but they also use the 'node' binary name in their packages.

Resources