nrwl / nx

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

NX Storybook Plugin Error: Failed to Process Project Graph [Nx 18.3.4] #27257

Open akibarika opened 1 month ago

akibarika commented 1 month ago

Current Behavior

running yarn nx affected --base=.... --head=.... --target=lint --verbose on the ADO pipeline, results in this error:

NX   Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it. See errors below.

Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
  An error occurred while processing files for the @nx/storybook/plugin plugin.
    - .storybook/main.ts: Cannot find module 'node_modules/@core/dist/index.cjs'. Please verify that the package.json has a valid "main" entry
      Error: Cannot find module 'node_modules/@core/dist/index.cjs'. Please verify that the package.json has a valid "main" entry
          at tryPackage (node:internal/modules/cjs/loader:436:19)
          at Function.Module._findPath (node:internal/modules/cjs/loader:678:18)
          at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
          at Function.Module._resolveFilename (node_modules/tsconfig-paths/src/register.ts:115:36)
          at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue (node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
          at Function.resolve (node:internal/modules/cjs/helpers:116:19)
          at .storybook/utils.ts:39:42
          at Array.flatMap (<anonymous>)
          at getStoriesConfigForMonorepoPackages (.storybook/utils.ts:37:16)
          at Object.<anonymous> (.storybook/main.ts:20:51)

I tried upgrading Nx one version at a time:

./storybook/project.json

"lint": {
  "executor": "@nx/eslint:lint",
  "outputs": ["{options.outputFile}"],
  "options": {
    "lintFilePatterns": ["apps/storybook/**/*.{ts,tsx,js,jsx}"]
  }
}

I also checked the package.json file in @core module locally and index.cjs was there as well @core/package.json

{
  "name": "@core",
  "version": "2.0.0",
  "main": "dist/index.cjs",
  "module": "dist/index.js",
  "type": "module",
  "types": "dist/index.d.ts",
  "files": [
    "dist/**/*"
  ]
}

Expected Behavior

The command that was working before 18.3.4 should still work without any changes necessary.

GitHub Repo

No response

Steps to Reproduce

  1. See above for relevant config sections required
  2. Execute the target using nx via any command (eg: nx run)

Nx Report

Node   : 20.15.1
OS     : darwin-arm64
yarn   : 3.6.4

nx                 : 18.3.4
@nx/js             : 18.3.4
@nx/linter         : 18.3.4
@nx/eslint         : 18.3.4
@nx/workspace      : 18.3.4
@nx/cypress        : 18.3.4
@nx/devkit         : 18.3.4
@nx/eslint-plugin  : 18.3.4
@nx/react          : 18.3.4
@nx/storybook      : 18.3.4
@nrwl/tao          : 13.8.3
@nx/vite           : 18.3.4
@nx/web            : 18.3.4
@nx/webpack        : 18.3.4
typescript         : 5.0.4
---------------------------------------
Registered Plugins:
@nx/storybook/plugin
---------------------------------------
The following packages should match the installed version of nx
  - @nrwl/tao@13.8.3

To fix this, run `nx migrate nx@18.3.4`

Failure Logs

NX   Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it. See errors below.

Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
  An error occurred while processing files for the @nx/storybook/plugin plugin.
    - .storybook/main.ts: Cannot find module 'node_modules/@core/dist/index.cjs'. Please verify that the package.json has a valid "main" entry
      Error: Cannot find module 'node_modules/@core/dist/index.cjs'. Please verify that the package.json has a valid "main" entry
          at tryPackage (node:internal/modules/cjs/loader:436:19)
          at Function.Module._findPath (node:internal/modules/cjs/loader:678:18)
          at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
          at Function.Module._resolveFilename (node_modules/tsconfig-paths/src/register.ts:115:36)
          at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue (node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
          at Function.resolve (node:internal/modules/cjs/helpers:116:19)
          at .storybook/utils.ts:39:42
          at Array.flatMap (<anonymous>)
          at getStoriesConfigForMonorepoPackages (.storybook/utils.ts:37:16)
          at Object.<anonymous> (.storybook/main.ts:20:51)

Package Manager Version

No response

Operating System

Additional Information

No response

akibarika commented 1 month ago

I believe the fix might be related to this pull request: https://github.com/nrwl/nx/pull/23068. However, I am still encountering the issue now.

Another thought on @nrwl/tao@13.8.3: Even after running nx migrate nx@18.3.4, the version won't change.

ty

Coly010 commented 4 weeks ago

@akibarika I'll see what I can discover after some investigation.

The @nrwl/tao package is no longer used and can safely be removed if you have the nx package installed at the correct version for your workspace.

Coly010 commented 2 weeks ago

@akibarika Is there any way you can provide a minimal reproduction of this issue? I've been unable to reproduce it myself. From your error, it seems like storybook is resolving your package to your node_modules, rather than local system, which could indicate that a TS Paths plugin is missing somewhere in your storybook config. But that's a guess and I can't investigate further without some kind of reproduction

akibarika commented 2 weeks ago

Hi @Coly010, thanks for that. The team and I have decided to stay on version 18.3.4 for now. I will review the resolution you provided and update you later. Thanks!

github-actions[bot] commented 1 week 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! 🙏