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

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

Closed
1 of 4 tasks
mklueh opened this issue Oct 9, 2024 · 4 comments · Fixed by #28795

Comments

@mklueh
Copy link

mklueh commented Oct 9, 2024

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

  • @nrwl/devkit@19.6.0
  • @nrwl/tao@15.9.7

To fix this, run nx migrate nx@19.8.4

Failure Logs

No response

Package Manager Version

No response

Operating System

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

Additional Information

No response

@Coly010
Copy link
Contributor

Coly010 commented Oct 14, 2024

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
Copy link

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.

Copy link

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! 🙏

@github-actions github-actions bot added the stale label Oct 23, 2024
@Coly010 Coly010 closed this as completed in be7bfa4 Nov 5, 2024
FrozenPandaz pushed a commit that referenced this issue Nov 5, 2024
<!-- 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 -->
We switched to using `loadConfigFile` from `@nx/devkit` to load Nuxt
Config files when plugins were not isolated.
However, they are now, so we can use `loadNuxtConfig` again.

The effect of using `loadConfigFile` paired with Nuxt's auto-imports
resulted in inconsistent failures.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Use `loadNuxtConfig` when `NX_ISOLATE_PLUGINS=true`

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28506
Fixes #28374

(cherry picked from commit be7bfa4)
FrozenPandaz pushed a commit that referenced this issue Nov 5, 2024
<!-- 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 -->
We switched to using `loadConfigFile` from `@nx/devkit` to load Nuxt
Config files when plugins were not isolated.
However, they are now, so we can use `loadNuxtConfig` again.

The effect of using `loadConfigFile` paired with Nuxt's auto-imports
resulted in inconsistent failures.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Use `loadNuxtConfig` when `NX_ISOLATE_PLUGINS=true`

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28506
Fixes #28374

(cherry picked from commit be7bfa4)
Copy link

github-actions bot commented Dec 9, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants