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

Typescript metro plugin doesn't build project references #3343

Open
2 of 5 tasks
aspirisen opened this issue Sep 10, 2024 · 4 comments
Open
2 of 5 tasks

Typescript metro plugin doesn't build project references #3343

aspirisen opened this issue Sep 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@aspirisen
Copy link

What happened?

When you use project references TypeScript force you to build your source code. When you have clean codebase there are no builded files and @rnx-kit/metro-plugin-typescript throws error about that.

I think there should an option like in fork-ts-checker-webpack-plugin - { typescript: { build: true, mode: 'write-dts' } }

Ideally, just running metro should be enough, without separate running of tsc compliler

Affected Package

@rnx-kit/metro-plugin-typescript

Version

0.4.5

Which platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows

System Information

System:
  OS: macOS 14.6.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 9.35 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.7.0
    path: ~/.nvm/versions/node/v22.7.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v22.7.0/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v22.7.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/dima/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.3 AI-233.14808.21.2331.11842104
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/dima/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Steps to Reproduce

  1. Set-up typescript project references
  2. Add @rnx-kit/metro-plugin-typescript to your metro config
  3. Run expo ios

Code of Conduct

  • I agree to follow this project's Code of Conduct
@aspirisen aspirisen added the bug Something isn't working label Sep 10, 2024
@tido64
Copy link
Member

tido64 commented Sep 11, 2024

Hi, this sounds like a feature request rather than something not working correctly. @rnx-kit/metro-plugin-typescript does not run in build mode, hence it does not look at project references. It's only supposed to do type checking, not build.

If you're on a recent version of Metro and you're using package exports, have you tried adding a typescript condition? In your Metro config, you can enable unstable_enablePackageExports and set unstable_conditionNames to something like ['typescript', 'require', 'import', 'react-native']. This should tell Metro to look for .ts files instead and you won't have to build anything.

@aspirisen
Copy link
Author

@tido64 I am not sure that this issue is connected with packages export, as I understand the error is coming from typescript type checker itself.

As I understand the plugin is supposed to allow you to do type checking by metro, if you have project references you have to run tsc manually what makes usages of @rnx-kit/metro-plugin-typescript useless, because the plugin can't work without tsc running in separate terminal and this is already performing type checking

@tido64
Copy link
Member

tido64 commented Sep 11, 2024

@tido64 I am not sure that this issue is connected with packages export, as I understand the error is coming from typescript type checker itself.

It isn't. I'm saying there is a solution for your scenario with package exports that avoids building altogether.

I am not opposed to adding proper support for project references, but that will be an option that we have to add. I'm not sure of the scope of this work and will have to ask someone who knows these bits better than I do.

Out of curiousity, what is the error you're seeing?

@aspirisen
Copy link
Author

@tido64 I have this error in clean repo

iOS Bundling failed 2039ms index.js (2831 modules)
error: Error: ENOENT: no such file or directory, open '/Users/dima/projects/sandbox/tamagui-front/front-lib/design/core/DesignShell/index.d.ts'
    at Object.readFileSync (node:fs:441:20)
    at VersionedSnapshot.getSnapshot (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/lib/snapshot.js:20:42)
    at ExternalFileCache.getSnapshot (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/lib/cache.js:59:21)
    at Object.getScriptSnapshot (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/lib/project.js:24:123)
    at getOrCreateSourceFileByPath (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:149926:35)
    at Object.getOrCreateSourceFile (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:149922:14)
    at /Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:149843:42
    at Object.getSourceFileWithCache [as getSourceFile] (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:124074:24)
    at findSourceFileWorker (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:126535:23)
    at findSourceFile (/Users/dima/projects/sandbox/tamagui-front/node_modules/@rnx-kit/typescript-service/node_modules/typescript/lib/typescript.js:126451:20)

When I run tsc --build the error goes away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants