#Cannot find module or its corresponding type declarations

5 messages · Page 1 of 1 (latest)

civic kelp
#

Hi everybody 👋👋

Current behavior

I am currently using Nest.js in a turborepo monorepo as the backend to my mobile app and the web app. In order to be able to share zod schemas and their inferred types across all of them, I created an internal Just-in-Time package named @repo/types

I get the following errors when trying to import anything from @repo/types:

Cannot find module '@repo/ui' or its corresponding type declarations. (when hovering over the package in VSCode in apps/api/src/app.service.ts)

This one when trying to start the backend server using nest start:

src/util/relations/link-single.ts:1:36 - error TS2307: Cannot find module '@repo/types' or its corresponding type declarations.
  There are types at 'E:/Work/Freelance/Coding/Academi.fy/workspace/node_modules/@repo/types/src/index.ts', but this result could not be resolved under your current **'moduleResolution' setting**. Consider updating to **'node16', 'nodenext', or 'bundler'.**

1 import type { ZodLinkMethod } from '@repo/types';

The error messages indicate mismatched module and moduleResolution types. So I tried to set every module and moduleResolution type to NodeNext. After that I am getting the following error:

#
file:///E:/Work/Freelance/Coding/Academi.fy/workspace/packages/types/src/index.ts:1
export { LoginSchema, type LoginDto, type LoginReturn } from './auth/login.zod';
                           ^^^^^^^^

SyntaxError: Unexpected identifier 'LoginDto'
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:353:18)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1385:24)
    at Module._compile (node:internal/modules/cjs/loader:1536:5)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Module.require (node:internal/modules/cjs/loader:1311:12)

Node.js v22.14.0

Minimum reproduction code

https://github.com/Daanieeel/turborepo-minimal-reproduciton.git

Steps to reproduce

  1. install yarn
  2. yarn install
  3. yarn dev

Expected behavior

Nest.js should find the exported types and zod schemas and use them as a just-in-time package @repo/types. The types and schemas should then be transpiled by the app/backend (Nest.js) project.

NestJS version

10.0.0

Packages versions

[System Information]
OS Version : Windows 10.0.26100
NodeJS Version : v22.14.0
NPM Version : 11.3.0

[Nest CLI]
Nest CLI Version : 10.4.9

[Nest Platform Information]
platform-express version : 10.4.17
schematics version : 10.2.3
testing version : 10.4.17
common version : 10.4.17
core version : 10.4.17
cli version : 10.4.9

GitHub

Minimal reproduction for turborepo issue. Contribute to Daanieeel/turborepo-minimal-reproduciton development by creating an account on GitHub.

#

Node.js version

22.14.0

In which operating systems have you tested?

  • [x] macOS
  • [x] Windows (WSL)
  • [ ] Linux

Other

If any more information is needed or my approach is wrong, be sure to tell me!

Also, if there are any grave fundamental issues with the code (like typos, packages that are not installed etc.), please tell me, so I can fix the reproduction repo. I have a full, working (except for this bug) project that has been fully functional up until the point where I integrated it into the monorepo. However, I may have accidentally messed up when copying the code into the reproduction.

Other than that, thank you in advance for any contribution.

civic kelp
#

Okay, so for anybody wondering about the same issue: don't use the Nest.js CLI, use tsx src/main instead