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

Q: how to configure resolving tsconfig with workspace packages? #3446

Closed
kwonoj opened this issue Dec 31, 2024 · 8 comments
Closed

Q: how to configure resolving tsconfig with workspace packages? #3446

kwonoj opened this issue Dec 31, 2024 · 8 comments
Assignees

Comments

@kwonoj
Copy link

kwonoj commented Dec 31, 2024

Issue description or question

https://github.com/kwonoj/wallaby-workspace-test

When running jest via cli yarn test, tsconfig extending from workspace package

{
  "extends": "@test/tsconfig/tsconfig.json",
}

seems being resolved and jest.config.ts being parsed. In wallay, getting

jest.config.ts
    TSError: ⨯ Unable to compile TypeScript:
  error TS6053: File '@test/tsconfig/tsconfig.json' not found.
  
      at readConfigFileAndSetRootDir 

Is there a way to setup / configure to resolve workspace package's tsconfig?

Wallaby diagnostics report

{
  editorVersion: '1.96.2',
  pluginVersion: '1.0.401',
  editorType: 'VSCode',
  osVersion: 'darwin 24.2.0',
  nodeVersion: 'v20.15.1',
  coreVersion: '1.0.1673',
  pnp: '<not set>',
  pnpEsm: '<not set>',
  checksum: 'M2E1MjY5NDcyNmRkZDRjOTc1MTc5N2ZkNjhmNzNhYzUsMTc3NzkzOTIwMDAwMCww',
  config: { tests: [], files: [] },
  packageJSON: { dependencies: undefined, devDependencies: { '@test/jest': 'workspace:^', '@test/tsconfig': 'workspace:^', '@test/util': 'workspace:^' } },
  fs: { numberOfFiles: 0 },
  debug: [
    '2024-12-31T02:43:48.355Z project waiting for initial run signal\n',
    '2024-12-31T02:43:48.358Z model Initialization Completed: 124ms\n',
    '2024-12-31T02:43:48.401Z config Attempting automatic configuration for angular\n',
    '2024-12-31T02:43:48.403Z angular/cli config Angular CLI not found.\n',
    '2024-12-31T02:43:48.404Z config Finished attempting automatic configuration for angular (3ms)\n',
    '2024-12-31T02:43:48.404Z config Attempting automatic configuration for jest\n',
    "2024-12-31T02:43:48.514Z jest/config Error: Failed to read Jest configuration from '<homeDir>/github/wallaby-workspace-test/packages/pkg-core': Error: Jest: Failed to parse the TypeScript config file <homeDir>/github/wallaby-workspace-test/packages/pkg-core/jest.config.ts\n" +
      '  TSError: ⨯ Unable to compile TypeScript:\n' +
      "error TS6053: File '@test/tsconfig/tsconfig.json' not found.\n" +
      '\n' +
      '    at readConfigFileAndSetRootDir (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)\n' +
      '    at async readInitialOptions (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:403:13)\n' +
      '    at async readConfig (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:147:48)\n' +
      '    at async Object.readConfigs (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:424:26)\n' +
      '    at async Object.loadJest (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:504:1651)\n' +
      '    at async i (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:190:24974)\n' +
      '    at async Object.s.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:190:28468)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13133)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13018)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13018)\n' +
      '    at async Config.load (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:12958)\n' +
      '    at async Project.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:490:2644)\n' +
      '    at Object.loadJest (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:504:2106)\n' +
      '    at async i (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:190:24974)\n' +
      '    at async Object.s.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:190:28468)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13133)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13018)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13018)\n' +
      '    at async Config.load (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:12958)\n' +
      '    at async Project.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:490:2644)\n',
    '2024-12-31T02:43:48.514Z config Finished attempting automatic configuration for jest (110ms)\n',
    '2024-12-31T02:43:48.514Z config Attempting automatic configuration for vitest\n',
    '2024-12-31T02:43:48.515Z vitest/config Error: Vitest dependency not found.\n' +
      '    at Object.s.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:191:4077)\n' +
      '    at automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13141)\n' +
      '    at async automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13018)\n' +
      '    at async Config.load (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:12958)\n' +
      '    at async Project.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:490:2644)\n',
    '2024-12-31T02:43:48.515Z config Finished attempting automatic configuration for vitest (1ms)\n',
    '2024-12-31T02:43:48.515Z config Attempting automatic configuration for node:test\n',
    '2024-12-31T02:43:48.515Z vitest/config Error: Wallaby node:test integration requires Node.js 22.3.0 or higher.\n' +
      '    at Object.s.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:191:565)\n' +
      '    at automaticConfigurationProviders.reduce.Promise.resolve.success (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:13141)\n' +
      '    at async Config.load (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:138:12958)\n' +
      '    at async Project.configure (<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.401/wallaby8dc9dc/server.js:490:2644)\n',
    '2024-12-31T02:43:48.515Z config Finished attempting automatic configuration for node:test (0ms)\n',
    '2024-12-31T02:43:48.516Z model [ERROR] Failed to configure Wallaby:\n' +
      "  Automatic Jest configuration error: Failed to read Jest configuration from '<rootDir>': Error: Jest: Failed to parse the TypeScript config file <rootDir>/jest.config.ts\n" +
      '    TSError: ⨯ Unable to compile TypeScript:\n' +
      "  error TS6053: File '@test/tsconfig/tsconfig.json' not found.\n" +
      '  \n' +
      '      at readConfigFileAndSetRootDir (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)\n' +
      '      at async readInitialOptions (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:403:13)\n' +
      '      at async readConfig (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:147:48)\n' +
      '      at async Object.readConfigs (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:424:26)\n' +
      '  Automatic Vitest configuration error: Vitest dependency not found.\n' +
      '  Automatic node:test configuration error: Wallaby node:test integration requires Node.js 22.3.0 or higher.\n' +
      '\n' +
      '  Please refer to our docs: https://wallabyjs.com/docs/config/overview.html \n',
    "2024-12-31T02:43:48.516Z project Failed to load configuration file: Automatic Jest configuration error: Failed to read Jest configuration from '<rootDir>': Error: Jest: Failed to parse the TypeScript config file <rootDir>/jest.config.ts\n" +
      '  TSError: ⨯ Unable to compile TypeScript:\n' +
      "error TS6053: File '@test/tsconfig/tsconfig.json' not found.\n" +
      '\n' +
      '    at readConfigFileAndSetRootDir (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)\n' +
      '    at async readInitialOptions (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:403:13)\n' +
      '    at async readConfig (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:147:48)\n' +
      '    at async Object.readConfigs (<homeDir>/github/wallaby-workspace-test/node_modules/jest-config/build/index.js:424:26)\n' +
      'Automatic Vitest configuration error: Vitest dependency not found.\n' +
      'Automatic node:test configuration error: Wallaby node:test integration requires Node.js 22.3.0 or higher.\n',
    '2024-12-31T02:43:48.520Z ui.service Starting UI service on port: 55000\n',
    '2024-12-31T02:43:48.521Z ui.service UI service started on port: 55000\n',
    '2024-12-31T02:43:48.624Z websocket received message ui.trackOverviewTestList\n',
    '2024-12-31T02:43:48.624Z websocket received method call: trackOverviewTestList\n',
    '2024-12-31T02:43:48.625Z websocket received message ui.trackAllLogsAndErrors\n',
    '2024-12-31T02:43:48.625Z websocket received method call: trackAllLogsAndErrors\n',
    '2024-12-31T02:43:48.625Z websocket received message ui.trackStatus\n',
    '2024-12-31T02:43:48.625Z websocket received method call: trackStatus\n',
    '2024-12-31T02:43:48.625Z websocket received message ui.trackTestRun\n',
    '2024-12-31T02:43:48.625Z websocket received method call: trackTestRun\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackStartupEvents\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackStartupEvents\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackStats\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackStats\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackStatus\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackStatus\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackTestRun\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackTestRun\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.handshake\n',
    '2024-12-31T02:43:48.626Z websocket received method call: handshake\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackEditorCursor\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackEditorCursor\n',
    '2024-12-31T02:43:48.626Z websocket received message ui.trackStatus\n',
    '2024-12-31T02:43:48.626Z websocket received method call: trackStatus\n',
    '2024-12-31T02:43:48.635Z websocket received message ui.untrackStats\n',
    '2024-12-31T02:43:48.635Z websocket received method call: untrackStats\n',
    '2024-12-31T02:43:48.635Z websocket received message ui.untrackStartupEvents\n',
    '2024-12-31T02:43:48.635Z websocket received method call: untrackStartupEvents\n',
    '2024-12-31T02:43:48.635Z websocket received message ui.untrackTestRun\n',
    '2024-12-31T02:43:48.635Z websocket received method call: untrackTestRun\n',
    '2024-12-31T02:43:48.719Z websocket received message ui.trackDiagnosticMessages\n',
    '2024-12-31T02:43:48.719Z websocket received method call: trackDiagnosticMessages\n'
  ]
}
@smcenlly
Copy link
Member

smcenlly commented Jan 1, 2025

Thanks for the sample repo.

We can't get the main branch of the sample repo to work for us, we get an error when using yarn test:

▪▪▪▪ pkg-util:test.jest (58e6ac6b)
▪▪▪▪ pkg-core:test.jest (d15124a7)
pkg-core:test.jest | Error: Jest: Failed to parse the TypeScript config file /Users/smcenlly/repos/temp/wallaby-workspace-test/packages/pkg-core/jest.config.ts
pkg-core:test.jest |   TSError: ⨯ Unable to compile TypeScript:
pkg-core:test.jest | error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
pkg-core:test.jest | 
pkg-core:test.jest |     at readConfigFileAndSetRootDir (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/@jest/core/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)
pkg-core:test.jest |     at readInitialOptions (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/@jest/core/node_modules/jest-config/build/index.js:403:13)
pkg-core:test.jest |     at readConfig (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/@jest/core/node_modules/jest-config/build/index.js:147:48)
pkg-core:test.jest |     at readConfigs (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/@jest/core/node_modules/jest-config/build/index.js:424:26)
pkg-core:test.jest |     at runCLI (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/@jest/core/build/cli/index.js:151:59)
pkg-core:test.jest |     at Object.run (/Users/smcenlly/repos/temp/wallaby-workspace-test/node_modules/jest-cli/build/run.js:130:37)
▪▪▪▪ pkg-core:test.jest (401ms, d15124a7)
Error: task_runner::run_failed

  × Task pkg-core:test.jest failed to run.
  ╰─▶ Process jest failed: exit code 1

Are we missing something?


At a glance, we can see a few things missing from your setup:

  1. You need to either install specific jest dependencies, or else update the packageExtensions of your yarn configuration (refer to our docs) in order for Wallaby to correctly find and load jest when using yarn. It looks like you have @jest/reporter as a devDependency but not @jest/console.

  2. You need to configure jest to run using the CLI from your project root in order for Wallaby to work. It looks like you are using a custom task runner (moon), which Wallaby does not integrate with. You will need to add a jest configuration file in your mono-repo root and use the jest projects setting to specify which projects to run within your monorepo.

Once you complete these steps, you should be able to run yarn jest from the CLI and if that works, Wallaby should also work.

@kwonoj
Copy link
Author

kwonoj commented Jan 1, 2025

  1. Sorry, forgot to push the latest commit, updated example repo's main branch and confirmed with quick CI (https://github.com/kwonoj/wallaby-workspace-test/actions/runs/12567866870/job/35034834258)

  2. While setup uses custom build tools / task runner, this can be observed with yarn's workspaces as well. For this specific question, I do understand wallaby needs to be able to find config - but the question is not about those. In the example repo, I can use manual config selection either manually picking the explicit file, or using closest project in mono-repo, then wallay fails with attached error message that doesn't occur in cli invocation. Specifically, it fails to resolve the base tsconfig in the workspace package (@test/tsconfig/*).

If rules out task runner (moon), jest cli still works in either way

$> cd packages/pkg-core && yarn test-jest
$> yarn workspace @test/core run test-jest

But doesn't work

- cmd+shitf++
- select configuration
- custom directory
- choose packages/pkg-core

@smcenlly
Copy link
Member

smcenlly commented Jan 2, 2025

We're not quite sure why this isn't working for you, but we have identified that it works if you rename your configuration file to .js instead of .ts. This may be a short term workaround for you while we identify and fix why it's not working for .ts file extensions.

@kwonoj
Copy link
Author

kwonoj commented Jan 2, 2025

if you rename your configuration file to .js instead of .ts

Yes, I also noticed those too. Unfortunately, unlike the example repo I created, there are the actual TypeScript dependencies in the config file so it isn't easy to use js as a config.

@smcenlly
Copy link
Member

smcenlly commented Jan 2, 2025

In April 2024, we updated Wallaby's jest integration to always process TypeScript files with [email protected] using swc as the compiler. This significantly improved performance for large mono-repos with TypeScript jest configuration files. If I recall correctly, it means that the TypeScript compiler doesn't get created for each configuration file.

If we update your project to use [email protected], we get the same problem when using the CLI.

We have found a workaround that allows you to use [email protected] in your project both with Wallaby and from the CLI. This would allow you to use the current version of Wallaby with the performance optimization in place (which is our preference if it works for you).

To fix the problem in your sample project (after updating the project to use [email protected]) you need to change your tsconfig.json to reference the base configuration file:

packages/pkg-core/tsconfig.json

{
  "extends": "../../node_modules/@test/tsconfig/tsconfig.base.json",
}

If you know a better way of doing this for your project, please let us know.

If you're not OK with the workaround, please let us know and we'll consider another option for you.

@kwonoj
Copy link
Author

kwonoj commented Jan 2, 2025

Thanks, that gives me a clue to explore further. It looks like there's an edge case to ts-node's config module resolution. I filed TypeStrong/ts-node#2146 and created a short workaround fix to the upstream itself.

I can apply a patch / workaround on the repo's ts-node dependency, but afaik wallaby manages dependency on its own, so I presume there's no way to apply custom patches on those. Am I understanding this correctly? If that's the case probably the other way of workaround is removing subpath exports, while it is still not ideal.

For the issue itself, I think it can be closed since this is more upstream issue. Still hope if there's a way to apply some patches to the wallaby's core but that's probably out of the scope.

@smcenlly
Copy link
Member

smcenlly commented Jan 3, 2025

We will take a look at your PR and do some testing early next week. If there are no issues, we'll apply a similar patch to our version of ts-node. We will keep this issue open until we've completed our investigation.

@smcenlly
Copy link
Member

smcenlly commented Jan 6, 2025

We've applied your PR to Wallaby's version of [email protected]. The latest version of Wallaby core (v1.0.1675) should now work for you.

@smcenlly smcenlly closed this as completed Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants