Closed zjkipping closed 1 year ago
Updated the example workspaces in the reproduction repo to be simplified. All the code is contained in the app.module.ts
now for the server
nest applications.
Was messing around with the different middlewares that the json-server
applies and running middlewares.splice(2, 1);
before applying the middlewares gets rid of the runtime error. This middleware function is [Function: errorHandler]
. I assume removing this isn't great (since the error could be happening still, but not be handled?), but I don't see why it has runtime errors all of a sudden with the bumping of the @nrwl/node
executor.
Looks like my previous comment has to do with the package: https://github.com/expressjs/errorhandler that json-server
directly adds to it's middlewares list that is returned by the defaults()
method.
So based on the stack trace I provided, it's failing here in the errorhandler
package: https://github.com/expressjs/errorhandler/blob/master/index.js#L115.
Going further into the stack trace it's failing here in the accepts
package: https://github.com/jshttp/accepts/blob/master/index.js#L100
So, what changed between these two nx
& @nrwl/node
versions that breaks this? It looks like the headers are undefined?
So, the reproduction could now look like this:
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import * as errorhandler from 'errorhandler';
@Module({})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
consumer.apply(errorhandler()).forRoutes('/');
}
}
Going to explore errorhandler
& accepts
packages and see what has happened.
Would appreciate help from anyone that knows more about this stuff :)
Personally can't make much of why things are suddenly broken... Going to just manually remove the errorhandler
middleware function and move forward with my projects Nx v15 upgrade.
Thank you for the detailed issue. Taking a look at this today
@nartc Any news on this front?
@zjkipping Sorry for the late response. The issue is actually from nrwl/node:webpack
-> nrwl/webpack:webpack
. In webpack:webpack
starting from 14.7.6, we assign a value to process.env.NODE_ENV
and json-server
adds errorHandler
middleware if this value is 'development'
. Why headers
is undefined is still unknown to me.
What trips us up (and probably you as well) is webpack:webpack
is the build
target instead of serve
target and we're trying to find issues in js:node
.
But with this find, I think this issue is a non-fix
since it does make sense to have process.env.NODE_ENV
in serve
context. I'd set process.env.NODE_ENV
to development
explicitly when you run json-server
?
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
UPDATE
This has to do with the
expressjs/errorhandler
middleware function thatjson-server
adds to it's middleware list.Get error
ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'accept')
at runtime when going to thejson-server
designated route in the Nest server in versions ofnx
&@nrwl/node
>=v14.7.6
.Expected Behavior
Should work as it has for many nx versions. Upgrading nest by itself changes nothing, we were on v8.x.x and going to 9.x.x doesn't result in this error. This is a direct result of the nx version & the
@nrwl/node
executor that the Nest server uses.Wondering what has changed with the executor or Nx that has caused this error.
Steps to Reproduce
UPDATE
https://github.com/zjkipping/nx-expressjs-errorhandler-issues
Can reproduce in a generated
Nest
application onlatest
nx
,nrwl/node
, and@nestjs
versions with the below code in theapp.module.ts
:https://github.com/zjkipping/nx-node-nest-issues The README should explain everything in the repo.
I created three workspaces. All 3 have the same Nest server setup (default generated) with
json-server
added and configured into theapp.module.ts
. There is a workspace for the version where things work (v14.7.5), one for where the runtime error starts (v14.7.6), and one for latest (v15.1.1).Go into any of the three workspaces & run
npm i
and thennpm start
. Navigate tohttp://localhost:3333/api/
to see the error response & then look at the terminal/console for the full error (if you are on a workspace with errors at runtime).The code in the
app.module.ts
for each workspace's nestserver
application:Failure Logs
Environment
Node : 18.12.0 OS : win32 x64 npm : 8.19.2
nx : 14.7.6 @nrwl/angular : Not Found @nrwl/cypress : Not Found @nrwl/detox : Not Found @nrwl/devkit : 14.7.6 @nrwl/eslint-plugin-nx : 14.7.6 @nrwl/expo : Not Found @nrwl/express : Not Found @nrwl/jest : 14.7.6 @nrwl/js : 14.7.6 @nrwl/linter : 14.7.6 @nrwl/nest : 14.7.6 @nrwl/next : Not Found @nrwl/node : 14.7.6 @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : Not Found @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : Not Found @nrwl/web : Not Found @nrwl/workspace : 14.7.6 typescript : 4.8.4
Local workspace plugins:
Community plugins: