-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nestjs app is served with --node-env=production
#26761
Comments
Having the same issue. The docs state that running |
Correcting my comment from earlier, I found that running the server target DID run the server in watch mode, but it uses the production build target first and restarts the build on subsequent file changes. This isn't a huge problem, but it can make it harder to decipher errors when you miss a provider. |
Same issue for me:
|
It appears to be forcefully passing I changed around some of the targets in {
"name": "server",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/server/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"defaultConfiguration": "production",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/server",
"webpackConfig": "apps/server/webpack.config.js"
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "server:build",
"runBuildTargetDependencies": false
},
"configurations": {
"development": {},
"production": {}
}
}
}
} // webpack.config.js
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');
console.log(process.env.NODE_ENV);
module.exports = {
output: {
path: join(__dirname, '../../dist/apps/server'),
},
stats: 'errors-only',
plugins: [
new NxAppWebpackPlugin({
target: 'node',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
generatePackageJson: process.env.NODE_ENV === 'production',
sourceMap: process.env.NODE_ENV === 'development',
}),
],
}; |
haha, the solution is here: #21517 (comment) |
@cdoky This solution works up to the point of hot reload failing, as you mentioned earlier. Have you figured out a workaround for this? |
@morgnism you can use this solution: #21517 (comment), if you hot reload failed, you can fixed it by |
I'm facing this issue with slow "hot reloading" (10x slower than before). You can try to edit this file in your node_modules (then run I guess there's an issue with the webpack configuration, webpack won't hot reloading because on each file change, it will build with production mode your app. IMO it should run a webpack-cli watch with dev mode and not rebuild the app. My webpack configuration that enable debug : const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');
module.exports = {
output: {
path: join(__dirname, '../../dist/apps/<your-app>'),
},
plugins: [
new NxAppWebpackPlugin({
target: 'node',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
sourceMap: process.env.ENV !== 'production',
}),
],
}; |
added this to my app project.json and breakpoints start to work. THANK you my friend!! All newcomers that will try to nestjs with NX now will not have breakpoints until they google that issue? that is very bad for such platform :( |
@slyk |
This is not fixing the mentioned problem. The dev mode should not try to EVER build any production libs. It makes the nx system completely unusable for small projects. I have one dependent library and a simple file change takes around 3 minutes before the dev server starts up again. The only reason is that it tries to build dependent libraries, which it should NEVER ever do in development mode. Even starting the nestjs service in production mode is flawed. Any input from the nx team? When is a fix to be expected? |
To enhance DX, you can use nest-cli for dev purposes like local serve.
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/<project-1>/src",
"monorepo": true,
"root": "apps/<project-1>",
"compilerOptions": {
"tsConfigPath": "apps/<project-1>/tsconfig.nest.json"
},
"projects": {
"<project-1>": {
"type": "application",
"root": "apps/<project-1>",
"entryFile": "main",
"sourceRoot": "apps/<project-1>/src",
"compilerOptions": {
"tsConfigPath": "apps/<project-1>/tsconfig.nest.json"
}
},
"<project-2>": {
"type": "application",
"root": "apps/<project-2>",
"entryFile": "main",
"sourceRoot": "apps/<project-2>/src",
"compilerOptions": {
"tsConfigPath": "apps/<project-2>/tsconfig.nest.json"
}
}
}
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/apps/<project-1>",
"module": "commonjs",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2021"
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
{
"name": "<project-1>",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/<project-1>/src",
"projectType": "application",
"tags": [],
"targets": {
...
"local": {
"executor": "nx:run-commands",
"options": {
"command": "nest start <project-1> --debug --watch --preserveWatchOutput"
}
}
}
}
"scripts": {
"dev": "nx run-many --all --target=local --output-style=stream-without-prefixes --verbose --parallel=<your number of projects>", (be aware that .env.local ou .env will be loaded)
"local": {
"executor": "nx:run-commands",
"options": {
"command": "nx serve <other-project>"
}
},
|
This does seem to work around the issues of utterly slow development mode times. I had to make some changes to the base tsconfig. I needed to remove the .ts ending from all path aliases. Thank you @rsaenen However, this can only be a workaround. Any new user of nx will instantly turn away from such slow development times. Something needs to be done here |
This worked for me, but still I do not like the solution. I feel like it has somewhat performance overhead due to My project.json
My WebPack:
|
Hi, thanks for filling out this issue. Yes, this is an actual issue the problem only occurs for the nest plugin which will be updated to ensure that your application can be built and served in dev mode. |
…ev (#29110) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Currently, when we generate a Nest application and run the serve target with development configuration the `node-env` is set to `production`. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Running the serve target in `development` should build the artifacts as `development` so they can be served correctly. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #26761 (cherry picked from commit 08a3307)
Current Behavior
When running
nx serve nestjsapp,
webpack builds it in a production mode.Expected Behavior
It should be served with
--node-env=development
.GitHub Repo
No response
Steps to Reproduce
See #22880
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: