0

I want run my backend api project with : nx serve api

this is my files :

project.json :

{
  "name": "api",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "packages/api/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/esbuild:esbuild",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "platform": "node",
        "outputPath": "dist/packages/api",
        "format": ["cjs"],
        "bundle": false,
        "main": "packages/api/src/main.ts",
        "tsConfig": "packages/api/tsconfig.app.json",
        "assets": ["packages/api/src/assets"],
        "generatePackageJson": true,
        "esbuildOptions": {
          "sourcemap": true,
          "outExtension": {
            ".js": ".js"
          }
        }
      },
      "configurations": {
        "development": {},
        "production": {
          "esbuildOptions": {
            "sourcemap": false,
            "outExtension": {
              ".js": ".js"
            }
          }
        }
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "api:build"
      },
      "configurations": {
        "development": {
          "buildTarget": "api:build:development"
        },
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    },
    "lint": {
      "executor": "@nx/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["packages/api/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "packages/api/jest.config.ts",
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    }
  },
  "tags": []
}

tsconfig.base.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
  },
  "exclude": ["node_modules", "tmp"]
}

package.json :

 {

"name": "@cell-ia/source", "version": "0.0.0", "license": "MIT", "scripts": {}, "private": true, "dependencies": { "@faker-js/faker": "^8.0.2", "@nx/react": "^16.2.2", "@types/bcrypt": "^5.0.0", "@types/cors": "^2.8.13", "@types/jsonwebtoken": "^9.0.2", "@types/multer": "^1.4.7", "@types/uuid": "^9.0.1", "awilix": "^8.0.1", "awilix-express": "^8.0.0", "axios": "^1.0.0", "bcrypt": "^5.1.0", "cors": "^2.8.5", "dotenv": "^16.0.3", "express": "~4.18.1", "helmet": "^7.0.0", "jsonwebtoken": "^9.0.0", "multer": "^1.4.5-lts.1", "stripe": "^12.7.0", "tslib": "^2.3.0", "uuid": "^9.0.0" }, "devDependencies": { "@nx/esbuild": "16.2.2", "@nx/eslint-plugin": "16.2.2", "@nx/jest": "16.2.2", "@nx/js": "16.2.2", "@nx/linter": "16.2.2", "@nx/node": "16.2.2", "@nx/workspace": "16.2.2", "@types/express": "~4.17.13", "@types/jest": "^29.4.0", "@types/node": "~18.7.1", "@typescript-eslint/eslint-plugin": "^5.58.0", "@typescript-eslint/parser": "^5.58.0", "esbuild": "^0.17.17", "eslint": "~8.15.0", "eslint-config-prettier": "8.1.0", "jest": "^29.4.1", "jest-environment-node": "^29.4.1", "nx": "16.2.2", "nx-cloud": "latest", "prettier": "^2.6.2", "ts-jest": "^29.1.0", "ts-node": "10.9.1", "tsconfig-paths": "^4.2.0", "typescript": "~5.0.2" } }

nx.json:

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "tasksRunnerOptions": {
    "default": {
      "runner": "nx-cloud",
      "options": {
        "cacheableOperations": ["build", "lint", "test", "e2e"],
        "accessToken": "N2M2YmZmNjctMWE2NC00ZWY5LThiYzUtOTA2ODg5N2MxOTA3fHJlYWQtd3JpdGU="
      }
    }
  },
  "targetDefaults": {
    "build": {
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"]
    },
    "test": {
      "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
    },
    "lint": {
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json",
        "{workspaceRoot}/.eslintignore"
      ]
    }
  },
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
      "default",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/.eslintrc.json"
    ],
    "sharedGlobals": []
  },
  "workspaceLayout": {
    "appsDir": "packages",
    "libsDir": "packages"
  }
}

tsconfig.json :

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["node"]
  },
  "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
  "include": ["src/**/*.ts", "custom.d.ts"],
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  }
}

I have this error message when i run my project :

nx run api:serve:development

node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module 'src/app/middlewares/auth'
Require stack:
- /home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/app/users/adapters/api/users-controller.js
- /home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/app/router.js
- /home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/container-ioc.js
- /home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/main.js
- /home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._resolveFilename (/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/main.js:32:36)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.Module._load (/home/test/Téléchargements/Cell-iA/cell-ia/node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:18:31)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/app/users/adapters/api/users-controller.js:25:19)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/app/users/adapters/api/users-controller.js',
    '/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/app/router.js',
    '/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/container-ioc.js',
    '/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/packages/api/src/main.js',
    '/home/test/Téléchargements/Cell-iA/cell-ia/dist/packages/api/main.js'
  ]
}

Who can help me please ?

thx all

PS: I already install tsconfig-paths but i have the same issue

i run

nx serve api

dudoum
  • 3
  • 2

0 Answers0