nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.62k stars 2.36k forks source link

Unable to create nodes for app using plugin @nx/webpack/plugin #22016

Closed JoelDigbeu closed 5 months ago

JoelDigbeu commented 8 months ago

Current Behavior

I get the following error when i try to build my app using nx/webpack locally and in my Github Action jobs:

Inner Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at validateString (node:internal/validators:162:11) at Object.join (node:path:1175:7)

Unable to create nodes for apps/gateway/webpack.config.js using plugin @nx/webpack/plugin.

Expected Behavior

I expect a successful build in order to complete my github action job using @nx-tools/nx-container:build

GitHub Repo

No response

Steps to Reproduce

  1. Generate Nestjs app using nx/nest plugin
  2. Update your generated app project.json

project.json

{
    //...
    //...
    //...
   target: [
      "container": {
      "executor": "@nx-tools/nx-container:build",
      "dependsOn": ["build"],
      //...options
      }
    }
   ]

}
  1. Add a basic webpack config

webpack.config.js

const { join } = require('path')

module.exports = {
    output: {
        path: join(__dirname, '../../dist/apps/your-app-name'),
    },
    plugins: [
        new NxWebpackPlugin({
            target: 'node',
            compiler: 'tsc',
            main: './src/main.ts',
            tsConfig: './tsconfig.app.json',
            assets: ['./src/assets'],
            optimization: false,
            outputHashing: 'none',
            generatePackageJson: true,
        }),
    ],
}
  1. Update nx.json for inferred task

    nx.json

    
    {
    //...options,
    plugins: [
    {
    "plugin": "@nx/webpack/plugin",
    "options": {
    "buildTargetName": "build",
    "serveTargetName": "serve",
    "previewTargetName": "preview"
    }
    },
    ]
    }

5. Run  `(yarn | npm | pnpm) nx appName:container`

### Nx Report

```shell
NX   Report complete - copy this into the issue template

Node   : 20.11.1
OS     : linux-x64
pnpm   : 8.15.3

nx                 : 18.0.5
@nx/js             : 18.0.5
@nx/jest           : 18.0.5
@nx/linter         : 18.0.5
@nx/eslint         : 18.0.5
@nx/workspace      : 18.0.5
@nx/devkit         : 18.0.5
@nx/eslint-plugin  : 18.0.5
@nx/nest           : 18.0.5
@nx/node           : 18.0.5
@nx/playwright     : 18.0.5
@nx/react          : 18.0.5
@nx/remix          : 18.0.5
@nrwl/tao          : 18.0.5
@nx/vite           : 18.0.5
@nx/web            : 18.0.5
@nx/webpack        : 18.0.5
typescript         : 5.3.3
---------------------------------------
Community plugins:
@nx-tools/nx-container : 5.2.0

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

WarrenBuffering commented 8 months ago

I just ran into this when using npx to generate the project (i.e. npx nx g @nx/expo:app test-app) but then tried generating without npx (pnpm nx g @nx/expo:app test-app) and now the expo app is building just fine.

ntubrian commented 8 months ago

@WarrenBuffering thx a lot for saving my life lol

gabrielbryk commented 8 months ago

I am also having this issue but its only happening when i try running nx commands from within a target "serve-with-env": { "executor": "nx:run-commands", "options": { "commands": [ { "command": "./runEnv.sh" }, { "command": "nx serve frontend" } ], "parallel": false, "cwd": "apps/frontend/" } },

martialanouman commented 8 months ago

Hi, still no update on this issue?

smasala commented 8 months ago

Happens sporadically for me pnpm nx reset fixes it locally but not for the CI

smasala commented 8 months ago

The error can be fixed by updating all webpack.config.js and webpack.config.ts accordingly (depending on the project configurations you have).

  1. setup a clean repo add create apps with the desired nx plugins (react, nest etc)
  2. copy the contents of each webpack.config.ts and extend as needed.

    • for react applications extend withNx function in the webpack config with the required tsConfig path option
    import { join } from 'path';
    ....
    withNx({
    tsConfig: join(__dirname, 'tsconfig.app.json'),
    }),
  3. sync the project.json files with those out of the new repo, specifically the build and serve targets
  4. same goes for any webpack.config.js files if you've got apps that use the @nx/webpack:webpack or @nx/js:node plugin

Notes:

francisco-sanchez-molina commented 7 months ago

Hello! I've been investigating this problem; we have both React and Next.js applications, and the Next.js applications fail in CI. I've managed to replicate it locally with Docker, and I'm not sure if it's related to this:

https://github.com/nrwl/nx/blob/32144bb702b07eddf29ed70055dfbcbcc0f4b11c/packages/nx/src/project-graph/project-graph.ts#L303

By setting "useDaemonProcess": false in nx.json, I've made it also fail locally. However, with "useDaemonProcess": true in CI, I haven't been able to get it to work.

Coly010 commented 6 months ago

Thank you for bringing this issue to our attention! I want to assure you that I will take a look as soon as I can. Your patience and understanding in this matter is greatly appreciated.

Coly010 commented 5 months ago

Hi all, there seems to be a mix of different issues being reported here.

Node/Nest/Express projects do not currently support Inferred Tasks with Project Crystal. That was the original issue here. As it is not a supported feature, at least yet, I'm going to close this issue.

If others are still experiencing issues with React + Next, please open a new issue with a reproduction to allow us to investigate further.

Thank you!

github-actions[bot] commented 4 months ago

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.