Nx: Issues starting the project with node including the ts-node/register flag

Created on 30 Mar 2020  路  1Comment  路  Source: nrwl/nx

Expected Behavior

The command node --inspect=0.0.0.0:9229 -r ts-node/register apps/some-service/src/main.ts should successfully build the project, which at the certain files, imports the models from the libs/shared/... folder (starting location at the root of the project).
The importing should be done via paths, defined in the main tsconfig.json file.
That would allow me to debug the application in TypeScript (with source maps).

Current Behavior

When importing the models in the some-service from libs/shared folder, the NestJS application can not be built with node --inspect=0.0.0.0:9229 -r ts-node/register apps/some-service/src/main.ts anymore.

Failure Information (for bugs)

Error: Cannot find module '@shared/some'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\xxx\apps\some-service\src\app\some-service\some-service.controller.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Module.m._compile (C:\xxx\node_modules\ts-node\src\index.ts:439:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\xxx\node_modules\ts-node\src\index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:598:32)

Steps to Reproduce

  1. Scaffold the NestJS application.
  2. Create model in libs/shared/some.model.ts
  3. Define the paths in the root tsconfig.json file like this (under compilerOptions):
    藳json "paths": { "@shared/*": ["./libs/shared/*"] }

Context

````
NODE: 10.13.0
NPM: 6.1.0

"@nrwl/eslint-plugin-nx": "8.7.0",
"@nrwl/jest": "8.7.0",
"@nrwl/nest": "^8.7.0",
"@nrwl/node": "8.7.0",
"@nrwl/workspace": "8.7.0",
"@angular/core": "^8.2.12",
"@nestjs/cli": "^7.0.0",
"@nestjs/common": "^7.0.3",
"@nestjs/core": "^7.0.3",
"@nestjs/platform-express": "^7.0.3",
"@nestjs/swagger": "^4.4.0",
"@nestjs/typeorm": "^6.2.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.3",
"ts-node": "~7.0.0",
"typescript": "^3.7.2"
````

node bug

Most helpful comment

Please close the issue, it was not related to NX workspace nor NestJS.
What I needed to do, was including the flag to resolve paths in node command: -r tsconfig-paths/register.
Final command: node --inspect=0.0.0.0:9229 -r tsconfig-paths/register" -r ts-node/register apps/search/src/main.ts

>All comments

Please close the issue, it was not related to NX workspace nor NestJS.
What I needed to do, was including the flag to resolve paths in node command: -r tsconfig-paths/register.
Final command: node --inspect=0.0.0.0:9229 -r tsconfig-paths/register" -r ts-node/register apps/search/src/main.ts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZempTime picture ZempTime  路  3Comments

SWGeekPD picture SWGeekPD  路  3Comments

zachnewburgh picture zachnewburgh  路  3Comments

Svancara picture Svancara  路  3Comments

elliotmendiola picture elliotmendiola  路  3Comments