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

yarn with pnp fails on nx g @nx/js:lib (@nx/js tried to access @nx/eslint, but it isn't declared in its dependencies) #29125

Open
1 of 4 tasks
davidfiala opened this issue Nov 29, 2024 · 0 comments

Comments

@davidfiala
Copy link

Current Behavior

Ubuntu 24.10.01
Node v23.2.0
Yarn 4.5.3
Npm 10.9.0

When creating a fresh yarn project and then your first js lib, the js lib generation fails when yarn is set to use pnp. Upon reverting to node-modules nodeLinker, it works fine.

the tldr is that yarn nx g @nx/js:lib packages/foo --directory=packages/foo --bundler=tsc --strict=true --config=workspace when requesting eslint and jest results in:

Fetching @nx/eslint...

 NX   @nx/js tried to access @nx/eslint, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.


Required package: @nx/eslint (via "@nx/eslint/src/generators/utils/eslint-file")
Required by: @nx/js@virtual:125919fd1d1aa3e78dfd5781e4f57126e8d004810c5a3b52e7f0747a0b9b663fd19749894b1f3e9c7edd3f82b692feac44c3c171824113fc14578468118561e8#npm:20.1.4 (via .../.yarn/berry/cache/@nx-js-npm-20.1.4-4886d677f1-10c0.zip/node_modules/@nx/js/src/generators/library/)

Expected Behavior

yarn nx g @nx/js:lib should work regardless of nodeLinker being set to node-modules or pnp

GitHub Repo

No response

Steps to Reproduce

yarn create nx-workspace --preset=ts --interactive --workspaceType=package-based --pm=yarn
  select: prettier, no CI, no remote caching

cd <whatever name you chooes>

cat <<'EOF' >> .gitignore
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
EOF

git rm .yarn/install-state.gz
git clean -fX -d

# this is the killer line
echo "nodeLinker: pnp" > .yarnrc.yml

yarn

yarn nx g @nx/js:lib packages/foo --directory=packages/foo --bundler=tsc --strict=true --config=workspace
  select: eslint and jest as the choices


$ yarn nx g @nx/js:lib packages/foo --directory=packages/foo --bundler=tsc --strict=true --config=workspace

NX  Generating @nx/js:library

✔ Which linter would you like to use? · eslint
✔ Which unit test runner would you like to use? · jest
Fetching @nx/eslint...

 NX   @nx/js tried to access @nx/eslint, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.


Required package: @nx/eslint (via "@nx/eslint/src/generators/utils/eslint-file")
Required by: @nx/js@virtual:125919fd1d1aa3e78dfd5781e4f57126e8d004810c5a3b52e7f0747a0b9b663fd19749894b1f3e9c7edd3f82b692feac44c3c171824113fc14578468118561e8#npm:20.1.4 (via ...@nx-js-virtual-11e251092f/4/.../.yarn/berry/cache/@nx-js-npm-20.1.4-4886d677f1-10c0.zip/node_modules/@nx/js/src/generators/library/)

Require stack:
- /tmp/fail/blah/.yarn/__virtual__/@nx-js-virtual-11e251092f/4/.../.yarn/berry/cache/@nx-js-npm-20.1.4-4886d677f1-10c0.zip/node_modules/@nx/js/src/generators/library/library.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/config/schema-utils.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/command-line/run/executor-utils.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/devkit-internals.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/utils/assert-workspace-validity.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/project-graph/build-project-graph.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/project-graph/project-graph.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/project-graph/file-utils.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/utils/package-manager.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/src/utils/package-json.js
- /tmp/fail/blah/.yarn/unplugged/nx-virtual-a7567943e4/node_modules/nx/bin/nx.js
Pass --verbose to see the stacktrace.

We can salvage this and get success by reverting to nodeLinker: node-modules as seen here:

git clean -fX -d
echo "nodeLinker: node-modules" > .yarnrc.yml
yarn
yarn nx g @nx/js:lib packages/foo --directory=packages/foo --bundler=tsc --strict=true --config=workspace
  select: eslint, jest

...results in success

Nx Report

*** note *** even nx report fails with similar errors when pnp is on
*** note *** even nx report fails with similar errors when pnp is on
*** note *** even nx report fails with similar errors when pnp is on

see below for line like: Error: Your application tried to access jsonc-eslint-parser, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

-------

 NX   Report complete - copy this into the issue template

Node           : 23.2.0
OS             : linux-x64
Native Target  : x86_64-linux
yarn           : 4.5.3

nx                 : 20.1.4
@nx/js             : 20.1.4
@nx/jest           : 20.1.4
@nx/eslint         : 20.1.4
@nx/eslint-plugin  : 20.1.4
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
⚠️ Unable to construct project graph.
Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
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/eslint/plugin plugin.
    - packages/foo/eslint.config.js: Your application tried to access jsonc-eslint-parser, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

  Required package: jsonc-eslint-parser
  Required by: /tmp/fail/blah/packages/foo/

  Require stack:
  - /tmp/fail/blah/packages/foo/eslint.config.js
      Error: Your application tried to access jsonc-eslint-parser, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

      Required package: jsonc-eslint-parser
      Required by: /tmp/fail/blah/packages/foo/

      Require stack:
      - /tmp/fail/blah/packages/foo/eslint.config.js
          at require$$0.Module._resolveFilename (/tmp/fail/blah/.pnp.cjs:15082:13)
          at Function.<anonymous> (node:internal/modules/cjs/loader:1068:27)
          at require$$0.Module._load (/tmp/fail/blah/.pnp.cjs:14973:31)
          at TracingChannel.traceSync (node:diagnostics_channel:322:14)
          at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
          at Module.require (node:internal/modules/cjs/loader:1329:12)
          at require (node:internal/modules/helpers:136:16)
          at Object.<anonymous> (/tmp/fail/blah/packages/foo/eslint.config.js:16:15)
          at Module._compile (node:internal/modules/cjs/loader:1550:14)
          at Object.<anonymous> (node:internal/modules/cjs/loader:1702:10)
    An error occurred while processing files for the @nx/jest/plugin plugin.
    - packages/foo/jest.config.ts: ● Validation Error:

    Module @nx/jest/plugins/resolver in the resolver option was not found.
           <rootDir> is: /tmp/fail/blah/packages/foo

    Configuration Documentation:
    https://jestjs.io/docs/configuration

      Error: ● Validation Error:

        Module @nx/jest/plugins/resolver in the resolver option was not found.
               <rootDir> is: /tmp/fail/blah/packages/foo

        Configuration Documentation:
        https://jestjs.io/docs/configuration

Failure Logs

Package Manager Version

Ubuntu 24.10.01 Node v23.2.0 Yarn 4.5.3 npm 10.9.0

Operating System

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

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant