When trying to run the following code in ReactJS, I get the following error: Uncaught ReferenceError: process is not defined
. If I remove the const mongoose = require('mongoose');
line, everything works well. It's worth noting that I have installed mongoose
using the npm i mongoose
command (version 6.3.1
).
import logo from "./logo.svg";
import React, { Component } from 'react';
import "./App.css";
const mongoose = require('mongoose');
export default class Test extends React.Component {
render() {
return (
<div>
<p>Hey StackOverflow!</p>
</div>
);
}
}
What is the cause of this problem? Is it a problem with the mongoose
package specifically?
CodePudding user response:
Why do you need mongoose in your frontend code in the first place?
To answer your question specifically:
mongoose is using the global process
variable which is only available in a NodeJS context (e.g. a backend server application), not Browser context.