Comments (8)
I bet that mongoose-findorcreate is a CommonJS module. If you use import x from 'module'
, then the module 'module'
must have an export named default
which will be assigned to x
. However, a CommonJS module normally does not have an export named default
. The warning you are getting from VS Code is likely that there is no default
export from the module.
Instead, you likely want to do import * as findOrCreate from 'mongoose-findorcreate';
.
Please try this and let us know if that works!
from mongoose-findorcreate.
The error you posted is a TypeScript error. You need to learn/understand how vscode works: https://code.visualstudio.com/docs/nodejs/working-with-javascript . This is not a support forum for vscode. Sorry!
from mongoose-findorcreate.
Thanks a lot for the reference link and for taking the time to answer! I'm kind of new in Web Development so I appreciate very much your help.
from mongoose-findorcreate.
Yes, there are a lot of technologies that come together for web development, so it is not always clear where errors come from. Do let us know if you encounter any issue with this plugin behaving incorrectly. We will help as we have time (which is a very scarce resource x.x).
from mongoose-findorcreate.
I bet that mongoose-findorcreate is a CommonJS module. If you use
import x from 'module'
, then the module'module'
must have an export nameddefault
which will be assigned tox
. However, a CommonJS module normally does not have an export nameddefault
. The warning you are getting from VS Code is likely that there is nodefault
export from the module.Instead, you likely want to do
import * as findOrCreate from 'mongoose-findorcreate';
.Please try this and let us know if that works!
Thanks a lot for the explanation! Both ways work and don't affect the functionality, it still runs without errors. But the warning persists.
I attach an image of the warning here:
from mongoose-findorcreate.
@naufragotech The issue is that youβre using TypeScript. If you use JavaScript, you will not get a warning like that. If you are using TypeScript, it is your responsibility to understand what that means when consuming a package which is JavaScript and does not provide its own typings (such as mongoose-findorcreate
).
from mongoose-findorcreate.
@binki I'm not using TypeScript. You can see my entire code below:
`//jshint esversion:6
import "dotenv/config";
import express from "express";
import ejs from "ejs";
import mongoose from "mongoose";
import session from "express-session";
import passport from "passport";
import passportLocalMongoose from "passport-local-mongoose";
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
import findOrCreate from "mongoose-findorcreate";
const app = express();
app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(session({
secret: "Secret testing",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect("mongodb://localhost:27017/userDB", { family: 4 });
const userSchema = new mongoose.Schema({
username: String,
password: String,
});
userSchema.plugin(passportLocalMongoose);
userSchema.plugin(findOrCreate);
const User = new mongoose.model("User", userSchema);
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
passport.use(new GoogleStrategy({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "https://localhost:3000/auth/google/secrets",
userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo"
},
function (accessToken, refreshToken, profile, cb) {
User.findOrCreate({ googleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
app.get("/", (req, res) => {
res.render("home");
});
app.get("/auth/google", passport.authenticate('google', {
scope: ['profile']
}));
app.get('/auth/google/secrets',
passport.authenticate('google', { failureRedirect: '/login' }),
function (req, res) {
// Successful authentication, redirect home.
res.redirect('/secrets');
});
app.route("/login")
.get(async (req, res) => {
res.render("login");
})
.post(async (req, res) => {
const user = new User({
username: req.body.username,
password: req.body.password
});
req.login(user, function (err) {
if (err) {
console.log(err);
} else {
passport.authenticate("local")(req, res, function () {
res.redirect("/secrets");
});
}
})
});
app.route("/register")
.get(async (req, res) => {
res.render("register");
})
.post(async (req, res) => {
User.register({ username: req.body.username }, req.body.password, function (err, user) {
if (err) {
console.log(err);
res.redirect("/register");
} else {
passport.authenticate("local")(req, res, function () {
res.redirect("/secrets");
});
}
});
});
app.get("/secrets", (req, res) => {
if (req.isAuthenticated()) {
res.render("secrets");
} else {
res.redirect("/login");
}
});
app.get("/logout", function (req, res) {
req.logout(function (err) {
if (err) {
console.log(err);
} else {
res.redirect("/");
}
});
});
app.listen(3000, () => {
console.log("Server started on port 3000.");
});`
from mongoose-findorcreate.
@naufragotech updating the /auth/google route to
app.get('/auth/google',
passport.authenticate('google', {
scope: ['profile', 'email']
})
);
will help resolve the issue!
from mongoose-findorcreate.
Related Issues (16)
- Error with mongoose v5
- Pushing to arrays through upsert HOT 1
- Merging fields through upsert
- Promise does not resolve to Document HOT 1
- Bad documentation
- getting this.findOrCreate is not a function HOT 1
- document
- Could not find a declaration file for module 'mongoose-findorcreate'. HOT 14
- Race condition when doing findOrCreate for the same document simultaneously?
- Why are the properties that contain the dollar sign eliminated? HOT 1
- Mongoose findOrCreate not working
- why npm install mongoose-findorcreate failed HOT 1
- Not Compatible with the upcoming mongoose 7.0 HOT 1
- TypeError: Cannot read properties of undefined (reading 'ES6') HOT 1
- undefined ES6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-findorcreate.