Skip to content
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

node-env for @nx/nest app fails to build #29731

Open
1 of 4 tasks
nhhockeyplayer opened this issue Jan 23, 2025 · 2 comments
Open
1 of 4 tasks

node-env for @nx/nest app fails to build #29731

nhhockeyplayer opened this issue Jan 23, 2025 · 2 comments
Assignees
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@nhhockeyplayer
Copy link

nhhockeyplayer commented Jan 23, 2025

Current Behavior

SUBJECT: node-env search algorithm gets lost during build dev/prod

Hi, I have a repo thats traveled migration since nx@10. I use latest 20.3.3 to create a new workspace and then an @nx/nest app (nestjs api app). That nestjs app builds fine but its setup strange using run-commands and a new introduced args node-env. I took that project.json and used it as-is for my repo nestjs app previously generated by @nx/nest

generated project refers to node-env for args in generated project.json code
"args": ["node-env=production"]
no docs exist on this config or what dependent logic exists within NX to do its function
it is being handed off during task runs but that logi8c does not exist for my migrated 20.3.3 repo ???

algorithm falls searching in my repo at 20.3.3

figuring out why it works as-is with 20.3.3 has been tedious

I migrated my repo to 20.3.3 to no avail sifting thru all json config files

and its got to be some needle in the haystack config somewhere

ERROR in main
Module not found: Error: Can't resolve 'node-env=production' in '/Users/meanstack02/meanstacknh'
resolve 'node-env=production' in '/Users/meanstack02/meanstacknh'
  Parsed request is a module
  using description file: /Users/meanstack02/meanstacknh/package.json (relative path: .)
    resolve as module
      looking for modules in /Users/meanstack02/meanstacknh/node_modules
        single file module
          using description file: /Users/meanstack02/meanstacknh/package.json (relative path: ./node_modules/node-env=production)
            no extension
              /Users/meanstack02/meanstacknh/node_modules/node-env=production doesn't exist
            .js
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.js doesn't exist
            .json
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.json doesn't exist
            .wasm
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.wasm doesn't exist
        /Users/meanstack02/meanstacknh/node_modules/node-env=production doesn't exist
      /Users/meanstack02/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory


api build blocked

Expected Behavior

build should be graceful

dropping .env and local.env config files within the scaffold fails to remedy

GitHub Repo

https://github.com/nhhockeyplayer

Steps to Reproduce

  1. create nx workspace preferably angular integrated for multiple apps frontend and backend
  2. create a demo app for angular (optional)
  3. create an api app using @nx/nest using nx-console or terminal command line as follows:

/Users/meanstack02/new/2025/january/node_modules/.bin/nx g @nx/nest:application --directory=api --name=api --no-interactive --dry-run

this generated code appears inside the generated code of @nx/nest generator

here is the project.json from new workspace 20.3.3 @nx/nest generator

{
  "name": "api",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/api/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "nx:run-commands",
      "options": {
        "command": "webpack-cli build",
        "args": ["node-env=production"]
      },
      "configurations": {
        "development": {
          "args": ["node-env=development"]
        }
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "dependsOn": ["build"],
      "options": {
        "buildTarget": "api:build",
        "runBuildTargetDependencies": false
      },
      "configurations": {
        "development": {
          "buildTarget": "api:build:development"
        },
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    }
  },
  "tags": []
}

Nx Report

nx report                                     

 NX   Report complete - copy this into the issue template

Node           : 22.9.0
OS             : darwin-x64
Native Target  : x86_64-macos
yarn           : 1.22.22

nx (global)            : 20.3.1
nx                     : 20.3.2
@nx/js                 : 20.3.2
@nx/jest               : 20.3.2
@nx/eslint             : 20.3.2
@nx/workspace          : 20.3.2
@nx/angular            : 20.3.2
@nx/cypress            : 20.3.2
@nx/devkit             : 20.3.2
@nx/esbuild            : 20.3.2
@nx/eslint-plugin      : 20.3.2
@nx/express            : 20.3.2
@nx/module-federation  : 20.3.2
@nx/nest               : 20.3.2
@nx/node               : 20.3.2
@nx/playwright         : 20.3.2
@nx/vite               : 20.3.2
@nx/web                : 20.3.2
@nx/webpack            : 20.3.2
nx-cloud               : 19.1.0
typescript             : 5.6.3
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/cypress/plugin
@nx/playwright/plugin
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@compodoc/compodoc               : 1.1.26
@fortawesome/angular-fontawesome : 1.0.0
@ionic/angular                   : 6.7.5
@jsverse/transloco               : 7.5.1
@ngrx/component                  : 19.0.0
@ngrx/component-store            : 19.0.0
@ngrx/effects                    : 19.0.0
@ngrx/entity                     : 19.0.0
@ngrx/operators                  : 19.0.0
@ngrx/router-store               : 19.0.0
@ngrx/schematics                 : 19.0.0
@ngrx/store                      : 19.0.0
@ngrx/store-devtools             : 19.0.0
@nxext/capacitor                 : 20.1.0
@nxext/ionic-angular             : 20.0.5
angular-eslint                   : 19.0.2
apollo-angular                   : 8.0.0

Failure Logs

NODE_ENV=development nx run admin-api:build:development
   or
nx run admin-api:build:development
   or
nx build admin-api --configuration development 
    or
nx build admin-api

produces error for all NODE_ENV


=============================

ERROR in main
Module not found: Error: Can't resolve 'node-env=development' in '/Users/meanstack02/meanstacknh'
resolve 'node-env=development' in '/Users/meanstack02/meanstacknh'
  Parsed request is a module
  using description file: /Users/meanstack02/meanstacknh/package.json (relative path: .)
    resolve as module
      looking for modules in /Users/meanstack02/meanstacknh/node_modules
        single file module
          using description file: /Users/meanstack02/meanstacknh/package.json (relative path: ./node_modules/node-env=development)
            no extension
              /Users/meanstack02/meanstacknh/node_modules/node-env=development doesn't exist
            .js
              /Users/meanstack02/meanstacknh/node_modules/node-env=development.js doesn't exist
            .json
              /Users/meanstack02/meanstacknh/node_modules/node-env=development.json doesn't exist
            .wasm
              /Users/meanstack02/meanstacknh/node_modules/node-env=development.wasm doesn't exist
        /Users/meanstack02/meanstacknh/node_modules/node-env=development doesn't exist
      /Users/meanstack02/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

webpack 5.97.1 compiled with 1 error in 66 ms
Warning: command "webpack-cli build node-env=development" exited with non-zero status code
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Running target build for project admin-api failed

Failed tasks:

- admin-api:build:development

Hint: run the command with --verbose for more details.


 NX   Storing terminal outputs for admin-api:build:development with hash 11144559741634519947

View structured, searchable error logs at https://nx.app/runs/2JFVR964YY

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

@nhhockeyplayer
Copy link
Author

nhhockeyplayer commented Jan 25, 2025

project.json

This continues to be an issue preventing build in my repo

I created a new workspace 20.3.3, used @nx/nest to create 'admin-api' app and the project .json looks legit and runs fine. BUT I put that project.json into my own repo and it does fail to build with following error which I am trying to figure out what is causing this or what my repo is missing for this to work.

I would like to get my admin-api nestjs app to build any tips are appreciated thank you

RunStart duration: 127
Entrypoint main =

ERROR in main
Module not found: Error: Can't resolve 'node-env=production' in '/Users/meanstack02/meanstacknh'
resolve 'node-env=production' in '/Users/meanstack02/meanstacknh'
  Parsed request is a module
  using description file: /Users/meanstack02/meanstacknh/package.json (relative path: .)
    resolve as module
      looking for modules in /Users/meanstack02/meanstacknh/node_modules
        single file module
          using description file: /Users/meanstack02/meanstacknh/package.json (relative path: ./node_modules/node-env=production)
            no extension
              /Users/meanstack02/meanstacknh/node_modules/node-env=production doesn't exist
            .js
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.js doesn't exist
            .json
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.json doesn't exist
            .wasm
              /Users/meanstack02/meanstacknh/node_modules/node-env=production.wasm doesn't exist
        /Users/meanstack02/meanstacknh/node_modules/node-env=production doesn't exist
      /Users/meanstack02/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

webpack 5.97.1 compiled with 1 error in 67 ms
Warning: command "webpack-cli build node-env=production" exited with non-zero status code
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Running target serve for project admin-api and 1 task it depends on failed

Failed tasks:

- admin-api:build

@nhhockeyplayer nhhockeyplayer changed the title NODE_ENV search algorithm incoherent during build dev/prod node-env for @nx/nest app fails to build Jan 25, 2025
@nhhockeyplayer
Copy link
Author

nhhockeyplayer commented Jan 26, 2025

yikes

this text sequence

.) obviously part of a regular expression

named inputs for production inside nx.json
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",

is showing up on generated package.json and project.json files from Nx

any comments from the Nx team?

Im continuing drilling into this to try some things

finding easily producible infinite loops that run the OS into boot crash

currently there is no functional nestjs project.json thats buildable
I understand Nx is a moving target but things can at least try to be more fault tolerant

this one is a blocker cant get my nestjs app building trying out all executors
have yet to debug my front end MFE boot up
looking forward to next patch release

@FrozenPandaz FrozenPandaz added the scope: node Issues related to Node, Express, NestJS support for Nx label Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

3 participants