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

Problem in Build Time: Could not resolve import "#nuxt/mongoose" #23

Closed AsbDaryaee closed 5 months ago

AsbDaryaee commented 9 months ago

Hi, I really appreciate your endeavors. I updated the the package to version 1.0.0 and in build time I get these errors:

[nitro] ℹ Building Nitro Server (preset: node-server) (node-resolve plugin) Could not resolve import "#nuxt/mongoose" in /app/server/models/message.model.ts using imports defined in /app/package.json. "#nuxt/mongoose" is imported by "server/models/message.model.ts", but could not be resolved – treating it as an external dependency.

Everything is fine in development but when I deploy the project, something goes wrong.

This is my schema (~/server/models/message.model.ts):

import { defineMongooseModel } from "#nuxt/mongoose";

export const MessageSchema = defineMongooseModel(
  "MessageSchema",
  {
    email: {
      type: "string",
      required: true,
    },
    firstName: {
      type: "string",
      required: true,
    },
    lastName: {
      type: "string",
      required: false,
    },
    phone: {
      type: "number",
      required: false,
      minlength: 6,
    },
    message: {
      type: "string",
      required: true,
      maxlength: 500,
    },
  },
  {},
  (schema) => {}
);
arashsheyda commented 9 months ago

Hi and thank you! Can you try to update to latest version 1.0.1?

AsbDaryaee commented 9 months ago

Hi and thank you! Can you try to update to latest version 1.0.1?

Sorry, I made a mistake about the version I'm using. It's v1.0.1 and the results are like above.

arashsheyda commented 9 months ago

Do you think it's possible for you to share your project with me? (doesn't need to be the whole project)

AsbDaryaee commented 9 months ago

Do you think it's possible for you to share your project with me? (doesn't need to be the whole project)

Of course, This is my repository

arashsheyda commented 9 months ago

Do you think it's possible for you to share your project with me? (doesn't need to be the whole project)

Of course, This is my repository

thank you! I will investigate and try to find the problem. thanks again

AsbDaryaee commented 9 months ago

thank you! I will investigate and try to find the problem. thanks again

Thanks to you dear Arash.

arashsheyda commented 9 months ago

well that's weird, lol. I build it and it's working, can you give me some more information ? npx nuxi info

the local build gives you error too or only when you deploy it? because I think you mentioned when I deploy the project, something goes wrong, which service provider are you deploying to? sorry for all these questions 😄 thanks

image

AsbDaryaee commented 9 months ago

Yes It works fine when I'm in development, even in my local computer works fine when I build the project same as yours. In deployment error occurs.

This is from my server:

Nuxt project info: 
------------------------------
- Operating System: Linux
- Node Version:     v18.17.1
- Nuxt Version:     3.7.3
- CLI Version:      3.9.0
- Nitro Version:    2.6.3
- Package Manager:  pnpm@8.7.6
- Builder:          -
- User Config:      modules, css, postcss, app, mongoose, vite
- Runtime Modules:  nuxt-mongoose@1.0.1
- Build Modules:    -
------------------------------

which service provider are you deploying to?

My project is going to launch on Liara

Many Thanks :)

arashsheyda commented 9 months ago

I see, I'll try to find the problem.

arashsheyda commented 8 months ago

hey @AsbDaryaee, can you DM me on twitter?

jackkoskie commented 8 months ago

@arashsheyda Hello! I'm having a very similar issue. I'm using version 1.0.2 and have followed the instructions in the docs

[6:04:47 PM] ERROR [worker reload] [worker init] Package import specifier "#nuxt/mongoose" is not defined in package /workspaces/CZQM-Site/package.json imported from /workspaces/CZQM-Site/models/User.js

// ~/models/User.js
import { defineMongooseModel } from '#nuxt/mongoose';

export const User = defineMongooseModel('User', {
  cid: {
    type: String,
    required: true,
  },
  personal: {
    type: Object,
    required: true,
  },
  vatsim: {
    type: Object,
    required: true,
  },
  flags: [String],
  bio: String,
});
// ~/nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {

  devtools: { enabled: true },
  modules: ['@sidebase/nuxt-auth', 'nuxt-mongoose'],

  mongoose: {
    uri: 'my-uri=here',
    options: {},
    modelsDir: 'models',
  },
});
// npx nuxi info
------------------------------
- Operating System: Linux
- Node Version:     v20.8.0
- Nuxt Version:     3.7.4
- CLI Version:      3.9.0
- Nitro Version:    2.6.3
- Package Manager:  npm@10.1.0
- Builder:          -
- User Config:      runtimeConfig, devtools, modules, auth, mongoose
- Runtime Modules:  @sidebase/nuxt-auth@0.6.0-beta.7, nuxt-mongoose@1.0.2
- Build Modules:    -
------------------------------
mrnasil commented 8 months ago

A new version of Nuxt Mongoose (v1.0.2) is available: https://github.com/arashsheyda/nuxt-mongoose/releases/latest

arashsheyda commented 8 months ago

I appreciate your patience and understand the frustration you're facing @AsbDaryaee, @jackkoskie. I've thoroughly tested the package on Vercel and a custom VDS, and it seems to be functioning as expected in both environments. Since the issue persists on your server only (it work on localhost), it's likely a server-specific configuration that's causing the error.

To assist you better, could you please provide more details about your server's configuration? I hope this helps!

jackkoskie commented 8 months ago

To assist you better, could you please provide more details about your server's configuration? I hope this helps!

Hey @arashsheyda! You mention it working on localhost however that is my issue, I am running it in dev mode on local host (github codespace). My environment is a 100% standard version of Ubuntu (latest lts version) with the latest stable version of node and npm as well as the latest stable versions of all standard packages. I will try it again in a completely empty repo however if two people are having the same issue then I'm going to guess the fix needs to be made within the package and not config side

arashsheyda commented 8 months ago

I will try it again in a completely empty repo however if two people are having the same issue then I'm going to guess the fix needs to be made within the package and not config side

Yes you are right, thank you for that.

jackkoskie commented 8 months ago

@arashsheyda It apears that the new update that was released (1.0.2) resolved this issue for me, in both the blank codebase and my actual codebase it works just fine in .2 but does not work in .1

Weird

I think you can consider this issue resolved

arashsheyda commented 8 months ago

@jackkoskie Yes, v1.0.1 encountered build errors, and the files were not fully uploaded to npm during the release.

PrimeTimeTran commented 7 months ago

I encountered this error after changing tsconfig.json & nuxt.config.ts

I wanted to setup Mongoose Zod.

Remove this from tsconfig.json

"compilerOptions": {
  "strict": true
}

Remove this from nuxt.config.ts

typescript: {
  typeCheck: true,
},

https://stackoverflow.com/questions/76986927/nuxt-mongoose-module-failed-to-resolve-import-nuxt-mongoose/77443524#77443524