nrwl / nx

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

@nx/nuxt/plugin config causing "Cannot read properties of undefined (reading 'split')" for one project not even using the plugin #28374

Open mklueh opened 2 weeks ago

mklueh commented 2 weeks ago

Current Behavior

First of all, please please please make the logs of this error more detailed! Me and others have wasted days with this issue, walking totally in the dark and the only way to find the cause is pure trial and error!

So recently I was facing this error again "Cannot read properties of undefined (reading 'split')"

and tried to exclude my projects one by one using .nxignore

After I figured out, that it is only one of the projects causing it, it made no sense to me, so I modified my nx.json until I found out that this plugin configuration is causing the trouble:

    {
      "plugin": "@nx/nuxt/plugin",
      "options": {
        "buildTargetName": "build",
        "testTargetName": "test",
        "serveTargetName": "serve",
        "buildStaticTargetName": "build-static",
        "serveStaticTargetName": "serve-static"
      }
    },

This is the project.json of the affected app:

{
  "name": "my-app",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
  "tags": ["staging", "live"],
  "targets": {
    "lint": {
      "executor": "@nx/linter:eslint",
      "options": {
        "lintFilePatterns": ["apps/my-app/**/*.{js,jsx,ts,tsx,vue}"]
      }
    },
    "prepare": {
      "executor": "nx:run-script",
      "options": {
        "script": "prepare"
      },
      "dependsOn": [
        {
          "target": "prepack",
          "dependencies": true
        }
      ]
    },
    "test": {
      "executor": "nx:run-script",
      "options": {
        "script": "test",
        "projects": "self"
      },
      "dependsOn": [
        {
          "target": "prepare"
        },
        {
          "target": "prepack:stub",
          "dependencies": true
        }
      ]
    },
    "e2e": {
      "executor": "@nx/playwright:playwright",
      "outputs": ["{workspaceRoot}/dist/.playwright/apps/my-app/e2e"],
      "options": {
        "config": "apps/my-app/playwright.config.ts"
      },
      "dependsOn": [
        {
          "target": "test"
        }
      ]
    },
    "build": {
      "executor": "nx:run-script",
      "options": {
        "script": "build"
      },
      "dependsOn": [
        {
          "target": "prepack",
          "dependencies": true
        },
        {
          "target": "test"
        },
        {
          "target": "e2e"
        }
      ]
    },
    "deploy": {
      "executor": "nx:run-script",
      "options": {
        "script": "deploy"
      },
      "dependsOn": [
        {
          "target": "test"
        },
        {
          "target": "e2e"
        },
        {
          "target": "build"
        }
      ]
    },
    "deploy:production": {
      "executor": "nx:run-script",
      "options": {
        "script": "deploy"
      },
      "dependsOn": [
        {
          "target": "test"
        },
        {
          "target": "e2e"
        },
        {
          "target": "build"
        }
      ]
    },
    "dev": {
      "executor": "nx:run-script",
      "options": {
        "script": "dev"
      },
      "dependsOn": [
        {
          "target": "prepack:stub",
          "dependencies": true
        }
      ]
    },
    "verify": {
      "dependsOn": [
        {
          "target": "smoke"
        },
        {
          "target": "lighthouse"
        }
      ]
    },
    "lighthouse": {
      "executor": "nx:run-script",
      "options": {
        "script": "lhci autorun"
      }
    },
    "smoke": {
      "executor": "@nx/playwright:playwright",
      "outputs": ["{workspaceRoot}/dist/.playwright/apps/my-app/smoke"],
      "options": {
        "config": "apps/my-app/playwright.config.ts"
      }
    }
  }
}

As far as I'm aware of, I'm not even using anything of the plugin right now, so it doesn't make sense that this app especially is causing the problem. In fact, my other apps are very similar, except the playwright /lighthouse tasks.

Both the plugin config, and the project.json are identical to my production version, but other lines of my overall nx.json have changed.

Expected Behavior

  1. The log message should be clear and at least point to the related file, or even log the problematic config / plugin and app
  2. I'd expect this app to behave like all the others, and the whole thing feels like a race condition, but maybe I made a mistake somewhere unaware of

GitHub Repo

No response

Steps to Reproduce

As far as I can tell, in my case the plugin config in my nx.json is enough to cause the issue with the one app, but I'm not sure this is reproducible, as the issue doesn't make sense in my opinion.

Nx Report

Node : 22.9.0 OS : win32-x64 Native Target : x86_64-windows yarn : 4.5.0

nx : 19.8.4 @nx/js : 19.8.4 @nx/jest : 19.8.4 @nx/linter : 19.8.4 @nx/eslint : 19.8.4 @nx/workspace : 19.8.4 @nx/devkit : 19.8.4 @nrwl/devkit : 19.6.0 @nx/esbuild : 19.8.4 @nx/eslint-plugin : 19.8.4 @nx/express : 19.8.4 @nx/node : 19.8.4 @nx/nuxt : 19.8.4 @nx/playwright : 19.8.4 @nrwl/tao : 15.9.7 @nx/vite : 19.8.4 @nx/vue : 19.8.4 @nx/web : 19.8.4 @nx/webpack : 19.8.4 typescript : 5.6.2

Registered Plugins: @nx/vite/plugin @nx/eslint/plugin @nx/playwright/plugin

Community plugins: @jnxplus/nx-gradle : 1.11.1 @nxlv/python : 19.1.3 @theunderscorer/nx-semantic-release : 2.12.0

The following packages should match the installed version of nx

To fix this, run nx migrate nx@19.8.4

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

Coly010 commented 1 week ago

Without a repo this is going to be tough to debug.

The plugin config you have in your nx.json is going to find all nuxt config files and attempt to create targets for a project at that directory.

If you only use a project.json and not anything inferred by this plugin, you can remove it from your nx.json. Otherwise, you can add exclude: ["path/to/project"] to the plugin definition in nx.json to avoid that directory when searching for config files.

It might help to understand how the project graph is created now.

  1. Load plugins from nx.json
  2. For Each Plugin in nx.json, glob the workspace for the appropriate config files
  3. Using the config file (by requiring, importing or ASTing it), infer targets for a project at that directory
  4. Glob the workspace for project.json/package.json files
  5. Apply targets defined in project.json/package.json for a project at that directory (overwriting what is inferred by the plugin earlier)

You can read more about Project Crystal here: https://nx.dev/concepts/inferred-tasks

Generally, everything here is working as expected, however, there could be an issue in the @nx/nuxt/plugin where it is assuming something is defined in the nuxt config which is actually missing for your nuxt config file. But that's going to be hard to tell without a repo.

nyarthan commented 1 week ago

This might only be tangentially related, but for me the issue was an implicit import of defineNuxtConfig in nuxt.config.ts. The error nx printed was just undefined but after changing the nuxt config to .js the error included more details.

So adding import { defineNuxtConfig } from 'nuxt/config'; to nuxt.config.ts solved the issue for me.

github-actions[bot] commented 3 days ago

This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏