arashsheyda / nuxt-mongoose

A Nuxt module for simplifying the use of Mongoose in your project.
https://docs.arashsheyda.me/nuxt-mongoose
69 stars 11 forks source link

nuxt-mongoose module: Failed to resolve import "#nuxt/mongoose" #18

Closed SignorPollito closed 10 months ago

SignorPollito commented 10 months ago

I'm trying to integrate my Nuxt project with the nuxt-mongoose module, but I'm encountering a problem, even if I've followed all the steps.

First of all I installed the package npm install nuxt-mongoose -D

Then I set up the .env and nuxt.config.ts

// nuxt.config.ts

export default defineNuxtConfig({
  devtools: { enabled: true },

  css: [
    'vuetify/styles/main.sass'
  ],

  build: {
    transpile: ['vuetify']
  },

  modules: [
    'nuxt-mongoose',
  ],

  nitro: {
  },

  mongoose: {
    uri: process.env.MONGODB_URI,
    options: {},
    modelsDir: 'models'
  }
})

So I created a schema, following the wiki one

// server/models/user.schema.js

import {defineMongooseModel} from "#nuxt/mongoose"; //Here is where I'm getting the error

export const UserSchema = defineMongooseModel({
    name: 'UserSchema',

    schema: {
        name: {
            type: 'string',
            required: true,
        },

        email: {
            type: 'string',
            required: true,
            unique: true
        },

        password: {
            type: 'string',
            required: true
        }
    }
});

Even if I followed what's in the wiki, when running npm run dev, I'm getting this error:

ERROR  Failed to resolve 
import "#nuxt/mongoose" from "server\models\user.schema.js". 
Does the file exist?

I've checked and actually the module export exists and so the method used, so I don't know why it isn't working.

I've tried to remove the import {defineMongooseModel} from "#nuxt/mongoose" as seen in other internet pages, but then the error says that it doesn't find that method.

I've tryied to remove and install the package nuxt-mongoose multiple times, without success.

SignorPollito commented 10 months ago

That was caused by a mistake I made in the code, so there were no problems related to this module.

AsbDaryaee commented 9 months ago

That was caused by a mistake I made in the code, so there were no problems related to this module.

Could you please explain how did you solve the problem? I have the same issue and need help :)