How to use mongodb in a SvelteKit project? - sveltekit

I imported mongodb with import { MongoClient } from 'mongodb';, (version of mongodb is 4.0.0-beta.5) it works fine in svelte-kit dev and svelte-kit preview, but when I try to start the server with node build, it throws Error: Dynamic require of "os" is not supported. How can I configure sveltekit or vite to import mongodb in production?

I found that since vite only precompiles packages in dependencies (https://github.com/vitejs/vite/issues/162#issuecomment-629623566), mongodb should be in dependencies, not devDependencies.

Related

Why is Module not found from Moralis in Next.js

I am currently in the process of developing a dApp for a local business, however the moralis node module seems to have started to get buggy.
I am using Next.js & React with Yarn
i ran yarn add moralis with the error as
as a result the local server throws this error​
I have tried uninstalling package and reinstalling, removing yarn.lock and package-lock.
I have tried all the other locations available for the (import Moralis from "Location") spot.
it should look like this if you are using react moralis
const { Moralis } = useMoralis(). Right now you are importing it from the wrong path

Realm and React error. Can't resolve 'react-native' in app created with create-react-app

I'm attempting to add the Realm package to a project created with create-react-app. I simply run the create script, install the project, then install realm. When I attempt to import or require 'realm' I get a Can't resolve 'react-native' error.
npx create-react-app my-app
cd my-app
npm i
npm i --save realm
npm start
At this point, if I attempt to import realm anywhere in the project, for instance by adding:
import Realm from 'realm';
or
Realm = require('realm');
to App.js or Index.js
I get the following error.
./node_modules/realm/lib/browser/index.js
Module not found: Can't resolve 'react-native' in '/Users/scolobey/Desktop/Projects/realm-blog/node_modules/realm/lib/browser'
As far as I have been able to tell, this seems to be related to webpack. Opening the console on this error page, I see:
./node_modules/realm/lib/browser/index.js
Module not found: Can't resolve 'react-native' in '/Users/scolobey/Desktop/Projects/javascript/my-app/node_modules/realm/lib/browser'
console.<computed> # index.js:1
r # backend.js:6
handleErrors # webpackHotDevClient.js:173
push../node_modules/react-dev-utils/webpackHotDevClient.js.connection.onmessage # webpackHotDevClient.js:212
Create React App is for regular React apps (not mobile/“React Native” apps). Your app is complaining because it expects to find the “react-native” package, which doesn’t come included with Create React App.
You’ll note that Realm’s Installation Guide specifically instructs you to set up react native before installing the package.
As mentioned in the React Native Docs - Getting Started (which is linked to in the above Realm installation guide), you likely want to use expo instead of Create React App.
Once the React Native app is set up, you can proceed with installing Realm.

SCRIPT438: Object doesn't support property or method 'setPrototypeOf'

I've created a react app using "create-react-app" command and updated all packages in package.json, App was not working in IE(any version) but after adding #babel/polyfil dependecy, it worked with IE-11, but facing problem with IE-10 and older version.
SCRIPT438: Object doesn't support property or method 'setPrototypeOf'
Create React App requires polyfills to work on Internet Explorer. You should follow the official guide to make it work on IE 9, 10 or 11. At the time of this writing it requires the following steps:
Install react-app-polyfill via npm or yarn.
npm install react-app-polyfill
Import it in your code:
import 'react-app-polyfill/ie9';
// or
import 'react-app-polyfill/ie11';

React production build in a meteor app

i have developped an application React/Redux with the Meteor JS framework.
The installation of React in meteor is class (npm command) :
meteor npm install --save react
But when i check with the react-devtools extension, i see that React Version is the development build instead of production build.
(the message is "This page is using the development build of React. 🚧 ")
What have i to do to use the react production build instead in my meteor app ?
i already tried to set environnement variables :
export NODE_ENV='production'
but the result is the same.
Running the meteor with production flag e.g. meteor --production should mimic how the meteor app builds for production. To learn more about the deployment of the meteor apps read the meteor guide about deployment and monitoring.
this issue is solved with the Meteor version 1.5.1 (using the --production flag)
now i obtain this message : This page is using the production build of React. ✅

Unknown module "Firebase" in React native

I am working on some sample apps using react native. I am trying to integrate Firebase plugin followed by firebase tutorial.
I can able to add firebase plugin using
npm install firebase --save
It gets added to node_modules, when i try to require the plugin
var Firebase = require('firebase');
It throws an exceptions "Requiring unknown module 'firebase'...."
First, make sure you've installed the dependency with:
npm install firebase --save
(make sure you are in your project folder)
Then end the NPM process and restart by running react-native start. That should do the trick.

Resources