Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve module/server/api from package in monorepo #20998

Closed
kzotov opened this issue May 22, 2023 · 4 comments
Closed

Can't resolve module/server/api from package in monorepo #20998

kzotov opened this issue May 22, 2023 · 4 comments

Comments

@kzotov
Copy link

kzotov commented May 22, 2023

Environment

Operating System: Darwin
Node Version: v18.13.0
Nuxt Version: 3.4.2 (But same with 3.5.1)
Nitro Version: 2.3.3
Package Manager: pnpm@8.4.0
Builder: vite
User Config: modules
Runtime Modules: nuxt-icon@0.4.0, @pinia/nuxt@0.4.9
Build Modules: -

Reproduction

I have a monorepo with custom modules and some packages

modules
|-custom-module-name
   |-src
     |-runtime
       |-server
         |-api
           |-healthcheck.get.ts
packages
|-package-name

At the packages i've using custom module, which contains module/custom-module-name/server/api/healthcheck.get.ts file.

Module setup file modules/custom-module-name/src/module.ts:

import { addServerHandler, defineNuxtModule } from '@nuxt/kit';

export interface ModuleOptions {}

export default defineNuxtModule<ModuleOptions>({
  setup(options, nuxt) {
    addServerHandler({
      route: '/api/healthcheck',
      handler: resolve(runtimeDir, 'server/api/healthcheck.get.ts'),
    });
  },
});

healthcheck.get.ts:

const startTime = new Date();

export default defineEventHandler(() => {
  return {
    status: 'success',
    uptime: process.uptime(),
    upSince: startTime,
    localTime: new Date(),
    env: {
      nodeEnv: process.env.NODE_ENV,
      pid: process.pid,
    },
  };
});

Describe the bug

It works fine at dev environment: http://localhost:3000/api/healthcheck

But when it builds, there is warnings:

"[path]/modules/custom-module-name/dist/runtime/server/api/healthcheck.get.ts" is imported by "virtual:#internal/nitro/virtual/server-handlers", but could not be resolved – treating it as an external dependency.

Additional context

No response

Logs

packages/package-name build: [nuxt] pages:extend: 0.188ms
packages/package-name build: [nuxt] build:manifest: 15.374ms
packages/package-name build: [nuxt] vite:compiled: 0.013ms
packages/package-name build: ✔ Server built in 8490ms
packages/package-name build: [nuxt] schema:beforeWrite: 0.02ms
packages/package-name build: [nuxt] schema:written: 0.035ms
packages/package-name build: [nuxt] nitro:build:before: 0.013ms
packages/package-name build: [nitro] ✔ Generated public .output/public
packages/package-name build: [nuxt] nitro:build:public-assets: 0.008ms
packages/package-name build: [nuxt] prerender:routes: 0.003ms
packages/package-name build: [nitro] prerender:routes: 0.08ms
packages/package-name build: [nitro] rollup:before: 0.011ms
packages/package-name build: [nitro] ℹ Building Nitro Server (preset: node-server)
packages/package-name build: "/Users/kzotov/projects/project-name/modules/custom-module-name/dist/runtime/server/api/healthcheck.get.ts" is imported by "virtual:#internal/nitro/virtual/server-handlers", but could not be resolved – treating it as an external dependency.
@danielroe
Copy link
Member

You should not add the .ts extension as this will not be present when you build your module.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2023
@kzotov
Copy link
Author

kzotov commented May 22, 2023

It works fine. Thank you.

@blowsie
Copy link
Sponsor Contributor

blowsie commented Dec 6, 2023

This caught me out too, since its that way in the documentation.
https://nuxt.com/docs/guide/going-further/modules#recipes

@vis97c
Copy link
Contributor

vis97c commented Feb 18, 2024

@danielroe Must be reopen or addressed somewhere else, as mentioned before, the docs are missleading in this regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants