nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.83k stars 7.65k forks source link

I get error when use just-in-time internal package with yarn workspaces #13934

Closed ikaasraa closed 2 months ago

ikaasraa commented 2 months ago

this my package and I want to use it in my nestjs app

{
  "name": "common",
  "version": "0.0.0",
  "exports": {
    ".": "./src/index.ts"
  },
  "private": true,
  "scripts": {
    "lint": "eslint --fix \"src/**/*.{ts,tsx}\""
  },
  "devDependencies": {
    "@nestjs/common": "^10.4.1",
    "@nestjs/config": "^3.2.3",
    "@nestjs/core": "^10.4.1",
    "@nestjs/graphql": "^12.2.0",
    "@nestjs/typeorm": "^10.0.2",
    "@types/node": "^22.5.1",
    "@typescript-eslint/eslint-plugin": "^8.3.0",
    "@typescript-eslint/parser": "^8.3.0",
    "eslint": "^8.57.0",
    "graphql": "^16.9.0",
    "reflect-metadata": "^0.2.2",
    "rxjs": "^7.8.1",
    "typeorm": "^0.3.20",
    "typescript": "^5.5.4"
  }
}

when I want to import in nestjs do not work well

I get this errr

[8:30:13 PM] Starting compilation in watch mode...

[8:30:15 PM] Found 0 errors. Watching for file changes.

node:internal/modules/cjs/loader:641
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/database' is not defined by "exports" in /Users/ikaaasra/Desktop/ALMAS/node_modules/@almas/common/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:651:9)
    at resolveExports (node:internal/modules/cjs/loader:634:36)
    at Module._findPath (node:internal/modules/cjs/loader:724:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
    at Module._load (node:internal/modules/cjs/loader:1051:27)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/ikaaasra/Desktop/ALMAS/packages/admin-server/src/app.module.ts:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1469:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.17.0
micalevisk commented 2 months ago

:warning: We use GitHub Issues to track bug reports, feature requests and regressions

Try the following instead: