I am trying to use express-session-mongo module in one of our projects. The code is exactly the same as seen on https://github.com/mikkel/express-session-mongo but I get "Cannot read property 'BSON' of undefined" error when I launch the app. Is there a module I forgot to require?
express-session-mongo tries to use the native bson parser for mongodb and that needs to be compiled separately.
Compiling the native parser inside the express-session-mongo directory solved it for me:
cd node_modules/express-session-mongo
npm install mongodb --mongodb:native
Related
I have a slight problem with a basic Node.JS method. When I'm trying to use "require()' method to import any downloaded (with 'npm install ..) module/library, I get a Visual Studio Code message that asks 'to convert 'require'(which is a Common JS module) into ES. If I do it, it transforms 'require()' into 'import..' though I want keep using 'require()'. Why is it so ? I read somewhere that Common JS is already included in the Node.JS environment though.
Then, when trying to compile my index.js file (with 'node index.js'), I obviously get an error about 'require' not recognized method.
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users...index.js from C:\Users...index.js not supported.
I tried then to install Webpack to fix this issue, but nothing change. I also kind of installed CommonJS (npm i common-js)..
Another common answer was to remove 'type':'module' from package.json file which normally should allow to use 'require', but I don't even have such a line in the file.
On top of that I've recently read that 'require' is not compatible with browser development tools (it's ok). But I'm trying to import a downloaded module/npm package in VSC terminal, not even in a browser.
As you understand I'm new to Node.JS, but I don't really get what's going on in this case...
I have created a brand new react app using VS2022 and create-react-app.
I have installed zlib using npm install zlib.
getting the following error when running npm run start:
ERROR in ./node_modules/zlib/lib/zlib.js 1:0-43
Module not found: Error: Can't resolve './zlib_bindings' in 'c:\projects\mall\mall\node_modules\zlib\lib'
To troubleshoot, I created a test.js file with just require('zlib') in it and it works.
file ./node_modules/zlib/lib/zlib.js has import './zlib_bindings' as a single line in it. But there is no ./zlib_bindings.js.
Questions:
How do I fix this?
How does that work when I run node test.js?
Your test.js file works because you run it with node.
The zlib module provides compression functionality implemented using
Gzip and Deflate/Inflate. It is the part of nodejs core module written
in c++
This module can't be used outside of node.js
You can however try to use react-zlib-js and it should work!
I'm attempting to use the fetch function in react-native to grab a piece of data from the web. from what I understand reading the docs, the fetch function is built in to react-native.
when doing so, I get the module resolution error in the attached screenshot, where for whatever reason the react-native bundler is attempting to use the fetch provided by typescript from my ~/.cache directory.
I've previously had typescript 2.6 installed globally via npm, I uninstalled it to see if that might fix things, but the error persists.
I should note that the only things I've done for this project are to create it with create-react-native-app, add a little snippet to the App.js component stolen from the react docs to fetch some JSON, and yarn run eject the project (this error persisted before and after the ejection)
well in my turkey-induced frenzy, it appears I hadn't properly uninstalled the global typescript install on my computer.
having done so properly, the issue is resolved;
however the issue of react-native's module resolution strategy being incompatible with a global typescript installation persists.
Just installed Mongo, mongodb driver and node. All current stable versions on a Ubuntu 14.04
mongo --version
MongoDB shell version: 3.2.1
node --version
v5.2.0
I'm pretty new to koa/mongo/node so I clone some github repos, but when I run code I always get this error:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Similar erros on stackoverflow are for older versions and there was either not clear solution or not working in my case.
How is the workflow? What is this extension for?
I tried reinstalling build-essential and node-gyp but without knowing the reason. Maybe is related to the monk or mongoose version if the projects are "old"?
You may be missing some build tools on your system.
In that case mongo driver will fallback to using a Javascript version of the bson parser, which is fine for development, but probably not in production.
Here is the solution:
cp ProjectDirectory/node_modules/monk/node_modules/mongodb/node_modules/bson/browser_build/bson.js ProjectDirectory/node_modules/monk/node_modules/mongodb/node_modules/bson/build/Release
I think you can use also move, I never tried.
The error message tell you bson.js is missing in "../build/Release folder", so you only have to put the file in the right place
I want to ask how can I add modul to node.js. I me I've installed node.js and want to create a simple form for uploading image. When I require a 'formidable' module and create a new object from it, i get an error 'cannot find the modul formidabe' .
Via npm (the node package manager), try this from your command line:
npm install formidable
as explained in the docs. After that it should work.