-
Notifications
You must be signed in to change notification settings - Fork 12
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
Explore Yarn PnP - Take 2 #755
Comments
$ yarn config get cacheFolder
/home/vscode/.yarn/berry/cache Storing the cache outside of the git workspace folder contributes to make git faster as git will have to do less work when it comes to |
As mentioned in the first ticket I opened about migrating to Yarn 2+ with PnP, some package may break if they don't specify their dependencies properly. I just bumped into this issue with I can installed |
❌ Jest is broken when using PnPMultiple tests are failing with the same error: ✖ nx run challenge-registry-org-search:test
FAIL web-org-search libs/challenge-registry/org-search/src/lib/org-search.component.spec.ts
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'resolvedFileName')
at module.exports (../../../../../home/vscode/.yarn/berry/cache/@nrwl-jest-npm-14.5.4-571814ec0a-8.zip/packages/jest/plugins/resolver.ts:85:22) See:
The issue is project specific:
TODO:
Running vscode@d8a8967a009a:/workspaces/challenge-registry/libs/challenge-registry/org-search$ yarn jest
FAIL web-org-search src/lib/org-search.component.spec.ts
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'resolvedFileName')
at module.exports (../../../.yarn/unplugged/@nrwl-jest-npm-14.5.4-571814ec0a/packages/jest/plugins/resolver.ts:85:22)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.559 s
Ran all test suites.
The file
The migration didn't success but trying my luck after Issue 1
Solution: Issue 2$ yarn nx run challenge-registry-challenge-search:test --skip-nx-cache
> nx run challenge-registry-challenge-search:test
> NX jest-preset-angular tried to access jest-util, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Required package: jest-util
Required by: jest-preset-angular@virtual:c90490eb2ad1863a8b234a152a63ef6b1e3395e58b6a870ee84e43041440f27fae9b212a409125e99a745ab235e9cd29b2c3141d8f30ed464f0452d2433a03f7#npm:12.2.2 (via /workspaces/challenge-registry/.yarn/__virtual__/jest-preset-angular-virtual-eac328e650/0/cache/jest-preset-angular-npm-12.2.2-5fbc5bb22d-0cb3738744.zip/node_modules/jest-preset-angular/build/config/)
Require stack:
- /workspaces/challenge-registry/.yarn/__virtual__/jest-preset-angular-virtual-eac328e650/0/cache/jest-preset-angular-npm-12.2.2-5fbc5bb22d-0cb3738744.zip/node_modules/jest-preset-angular/build/config/ng-jest-config.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-preset-angular-virtual-eac328e650/0/cache/jest-preset-angular-npm-12.2.2-5fbc5bb22d-0cb3738744.zip/node_modules/jest-preset-angular/build/ng-jest-transformer.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-preset-angular-virtual-eac328e650/0/cache/jest-preset-angular-npm-12.2.2-5fbc5bb22d-0cb3738744.zip/node_modules/jest-preset-angular/build/index.js
- /workspaces/challenge-registry/.yarn/cache/jest-util-npm-28.1.3-9ae2283a08-fd6459742c.zip/node_modules/jest-util/build/requireOrImportModule.js
- /workspaces/challenge-registry/.yarn/cache/jest-util-npm-28.1.3-9ae2283a08-fd6459742c.zip/node_modules/jest-util/build/index.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-config-virtual-e08a44d8a6/0/cache/jest-config-npm-28.1.1-8c4e855059-8ce9f6b8f6.zip/node_modules/jest-config/build/getCacheDirectory.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-config-virtual-e08a44d8a6/0/cache/jest-config-npm-28.1.1-8c4e855059-8ce9f6b8f6.zip/node_modules/jest-config/build/Defaults.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-config-virtual-e08a44d8a6/0/cache/jest-config-npm-28.1.1-8c4e855059-8ce9f6b8f6.zip/node_modules/jest-config/build/normalize.js
- /workspaces/challenge-registry/.yarn/__virtual__/jest-config-virtual-e08a44d8a6/0/cache/jest-config-npm-28.1.1-8c4e855059-8ce9f6b8f6.zip/node_modules/jest-config/build/index.js
- /workspaces/challenge-registry/.yarn/cache/@nrwl-jest-npm-14.8.3-0be5500c1d-65c2ed91ad.zip/node_modules/@nrwl/jest/src/executors/jest/jest.impl.js
- /workspaces/challenge-registry/.yarn/unplugged/nx-virtual-a6e8072397/node_modules/nx/src/config/workspaces.js
- /workspaces/challenge-registry/.yarn/unplugged/nx-virtual-a6e8072397/node_modules/nx/src/command-line/run.js
- /workspaces/challenge-registry/.yarn/unplugged/nx-virtual-a6e8072397/node_modules/nx/bin/run-executor.js
Pass --verbose to see the stacktrace. Solution: Issue 3$ yarn nx run challenge-registry-challenge-search:test --skip-nx-cache
> nx run challenge-registry-challenge-search:test
FAIL web-challenge-search libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts
● Test suite failed to run
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:1:34 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
1 import { HttpClientModule } from '@angular/common/http';
~~~~~~~~~~~~~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:2:40 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
2 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
~~~~~~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:3:43 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
~~~~~~~~~~~~~~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:8:1 - error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
8 describe('ChallengeSearchComponent', () => {
~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:12:3 - error TS2304: Cannot find name 'beforeEach'.
12 beforeEach(async () => {
~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:12:14 - error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
12 beforeEach(async () => {
~~~~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:21:3 - error TS2304: Cannot find name 'beforeEach'.
21 beforeEach(() => {
~~~~~~~~~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:27:3 - error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
27 it('should create', () => {
~~
libs/challenge-registry/challenge-search/src/lib/challenge-search.component.spec.ts:28:5 - error TS2304: Cannot find name 'expect'.
28 expect(component).toBeTruthy();
~~~~~~
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 6.678 s
Ran all test suites.
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Ran target test for project challenge-registry-challenge-search (11s) TODO:
|
Install Yarn SDK for VS Code$ yarn dlx @yarnpkg/sdks vscode
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 372ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ has-own-prop@npm:2.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ repeat-string@npm:1.6.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ tinylogic@npm:2.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ treeify@npm:1.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ typanion@npm:3.12.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0s 888ms
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 2s 476ms
➤ YN0000: ┌ Generating SDKs inside .yarn/sdks
➤ YN0000: │ ✓ Eslint
➤ YN0000: │ ✓ Prettier
➤ YN0000: │ ✓ Typescript
➤ YN0000: │ • 3 SDKs were skipped based on your root dependencies
➤ YN0000: └ Completed
➤ YN0000: ┌ Generating settings
➤ YN0000: │ ✓ Vscode (new ✨)
➤ YN0000: └ Completed This scans |
✔️ Issue related to
|
✔️ Accessing package type definition in VS CodeConsider However, it is not possible to open the definition file, which hinders package exploration and debugging. Note that I have already installed the Yarn SDK for VS Code. See:
WorkaroundUnplugging an npm package enables to access its code in VS Code. For example,
|
ConclusionI'm timeboxing the exploration of PnP to one day. The short answer is that our project can not use it yet mainly because there is still a lack of support from tools like VS Code, Nx, Jest, etc. PnP requires npm packages to be thorough when defining their dependencies. I could probably resolve these dependency issues if I had time. Instead, I'll wait 3-6 months before trying again. SetupHere is what I did to enable PnP and try to get it to work with this Nx workspace:
Unfortunately, running tests with Jest are now failing. Other considerations
Issues to monitor |
@tschaffter have you tried |
@hakimio I tried
What is your experience using |
The linked article talks about adding yarn pnp support to VS Code. I was referring to the issue you had with |
That seems strange - Jest has supported PnP for a while now, both codebases have tests to enforce it 🤔 |
I recently upgraded this monorepo to Yarn 2+, which greatly reduces the time required to install/update npm dependencies. One issue left unaddressed is the activation of the PnP mode generated an error. See #588 (comment). Using PnP should further reduce the runtime of Yarn locally and in CI/CD workflows.
Checklist
nx
instead ofyarn nx
.npm install
andnpm install --immutable
.References
pnpify
and Yarn SDK for VS Code.The text was updated successfully, but these errors were encountered: