Can run NestJS 6.0 as part of Nx workspace, and use Middleware functionality
When upgrading NestJS to 6.0 in NX workspace (7.6 or 7.8), when running in development mode adding Middleware to NestJS app either does not work (one controller) or causes controllers not to respond (multiple controllers)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Please provide detailed steps for reproducing the issue.
Repo used for these steps (it is in step 7-8 config) is here: https://github.com/kmkatsma/nx-nestjs6-middleware-issue
Please provide any relevant information about your setup:
angular.json
configuration - https://github.com/kmkatsma/nx-nestjs6-middleware-issue/blob/master/angular.jsonA minimal reproduce scenario using allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.
Please include any relevant log snippets or files here.
I know currently default Nx workspace uses NestJS 5.5, just hoping to be able to use 6.0 version of Nest in Nx workspace (really wanting the different injection scopes). I'm assuming this will need to wait for an update for Nx to use NestJS 6.0, just wanted to make sure this was out there to make sure this middleware scenario works after update.
I actually reverted to 5.5 version of NestJS and still had middleware issue. So not sure if people using NX with Nest are just running into and solving on their own.
I found that I was able to get around this particular issue by changing the global tsconfig compiler options to match those used by default in NestJS projects. A number of these settings are different than the default tsconfig options for NX workspace.
These are here:
"compilerOptions": {
"sourceMap": true,
"declaration": true,
"noImplicitAny": false,
"noLib": false,
"removeComments": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"module": "commonjs",
"typeRoots": ["node_modules/@types"],
"lib": ["es6", "es2015", "dom"],
"baseUrl": ".",
I'm thinking I will see if it's possible to override these for just the NestJS app itself, and will resolve issue...
Ok, this is best kind of issue - one that originator closes! I guess I just needed more time.
The solution was in fact to override the tsconfig for the NestJS app. The final version I am using looks like this below. It was also important to set the _baseUrl_ to the base of the monorepo, so that @ barrel files can be found. App is up and running, with middleware.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"],
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": false,
"target": "es6",
"module": "commonjs",
"typeRoots": ["node_modules/@types"],
"lib": ["es6", "es2015", "dom"],
"noImplicitAny": false,
"noLib": false,
"removeComments": true,
"allowSyntheticDefaultImports": true,
_"baseUrl": "./../../",_
},
"include": ["*/.ts"]
}
Thanks, faced exactly the same problem, changing the tsconfig.json
in the nest folder helped.
Most helpful comment
Ok, this is best kind of issue - one that originator closes! I guess I just needed more time.
The solution was in fact to override the tsconfig for the NestJS app. The final version I am using looks like this below. It was also important to set the _baseUrl_ to the base of the monorepo, so that @ barrel files can be found. App is up and running, with middleware.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"],
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": false,
"target": "es6",
"module": "commonjs",
"typeRoots": ["node_modules/@types"],
"lib": ["es6", "es2015", "dom"],
"noImplicitAny": false,
"noLib": false,
"removeComments": true,
"allowSyntheticDefaultImports": true,
_"baseUrl": "./../../",_
},
"include": ["*/.ts"]
}