How can I setup mongoose on deno+next.js app?
I have created a next.js project by following this tutorial: https://docs.deno.com/examples/next_tutorial/
Now how can I connect mongoose on this project?
I followed this tutorial: https://docs.deno.com/examples/mongoose_tutorial/ to add Mongoose to Deno+Next project but can't. Please see my attachment screenshot.
Do I need to install the Deno+Next.js project as a Mongoose dependency using the CLI?
Or it doesn't need to be installed using CLI. Directly importing it like this will work
import mongoose from "npm:mongoose@^6.7";
Deno
Build a Next.js App
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
Deno
How to use Mongoose with Deno
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
10 Replies
what's the error shown? Is there any output?
And yes, you do need to import it with
deno add npm:mongoose
Cannot find module 'npm:mongoose@8.9.2'
although I have installed it.
wait, so you do have a deno project set up?
or a npm one
deno add --allow-scripts npm:mongoose
it does preinstall scriptsIf I use, import mongoose from "mongoose"; then it's working. But in this tutorial: https://docs.deno.com/examples/mongoose_tutorial/ has imported like this,
import { model, Schema } from "npm:mongoose@^6.7";
Deno
How to use Mongoose with Deno
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
this is if you don't have a project setup
if you do have it, you just do
deno add npm:moongoose
(you can choose to allow scripts) then import it normallyNot working. I think we need to import like this for deno+next.js app.
import mongoose from "mongoose";
remove the version in the import doing it like this
import mongoose from "mongoose"
Yes. It's working I have already said that. But I have thought it will working like raw deno project. Just as shown here, https://docs.deno.com/examples/mongoose_tutorial/
Deno
How to use Mongoose with Deno
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
that's for when you don't have a project setup
if you do, it doesn't make sense to use it that way
but if you're forced to use it for whatever reason, you forgot the
^
in the version^
First time I was using this but it was not working. then I removed. And finally I'm using this, import mongoose from "mongoose"
and it's working.
Anyway, thank you very much for the response. @Sun「無用」 ❤️