react-native-css/metro's declarations import react-native, loading React Native's globals into a Node program

Đang mở Phù hợp với người mới
#549 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, react-native, typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu từ src/compiler/compiler.types.ts (dòng 8) và src/native/reactivity.ts (các dòng 1-8) để xem phần import VAR_SYMBOL kéo vào react-native. Chạy npx tsc -p . của repro với skipLibCheck: false để xác nhận 72 lỗi. Sửa lỗi là ngăn các khai báo kiểu import hằng số thời gian chạy từ phía native, sau đó xác minh metro.config.ts type-check mà không cần React Native globals.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Before submitting a new issue
  • I tested using the latest version of the library, as the bug might be already fixed.
  • I tested using a supported version of react native.
  • I checked for possible duplicate issues, with possible answers.
Bug summary

Typing a Metro config through react-native-css/metro (or nativewind/metro) loads React Native's types into a Node program. The compiler's declarations import a runtime constant from the native side: src/compiler/compiler.types.ts imports VAR_SYMBOL from ../native/reactivity, and src/native/reactivity.ts imports from react-native. React Native's declarations bring its runtime globals (fetch, AbortController, Blob, require…), which clash with @types/node's, so a metro.config.ts checked with skipLibCheck: false fails.

Library version

0.0.0-nightly.2421ea7 (main at 2421ea77da52), and 3.1.0-rc.0

Environment info
Windows 11 10.0.26300, Node 26.12.1, npm 12.2.1, TypeScript 7.0.2, @types/node 26.6.6, react-native 0.88.1.
No app or native build is involved: the errors come from the type check alone.
Steps to reproduce
  1. Clone the reproducible example: a metro.config.ts holding only import type {} from 'react-native-css/metro';, checked by a tsconfig.json with "types": ["node"] and skipLibCheck: false, beside react-native 0.88.1 and react-native-css 0.0.0-nightly.2421ea7.
  2. npm install --ignore-scripts
  3. npx tsc -p ., then npx tsc -p . --explainFiles to see why react-native is in the program.

Expected: no error; a Metro config's types reach no React Native type.

Actual: 72 errors in Node's and React Native's globals. The first ones:

node_modules/@types/node/module.d.ts(711,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'require' must be of type 'NodeRequire', but here has type 'Require'.
node_modules/@types/node/web-globals/abortcontroller.d.ts(43,15): error TS2300: Duplicate identifier 'AbortController'.
node_modules/@types/node/web-globals/abortcontroller.d.ts(44,9): error TS2300: Duplicate identifier 'AbortController'.
node_modules/@types/node/web-globals/abortcontroller.d.ts(50,15): error TS2300: Duplicate identifier 'AbortSignal'.
node_modules/@types/node/web-globals/abortcontroller.d.ts(51,9): error TS2300: Duplicate identifier 'AbortSignal'.

and --explainFiles shows where React Native comes from:

node_modules/react-native/types_generated/index.d.ts
   Imported via "react-native" from file 'node_modules/react-native-css/dist/typescript/module/src/native/reactivity.d.ts' with packageId 'react-native/types_generated/[email protected]+@types/[email protected][email protected]'
Reproducible example repository

https://github.com/YevheniiKotyrlo/react-native-css-metro-types-react-native

Ngôn ngữ chính
TypeScript
Star
166
Fork
45
Merge trung bình
10 ngày 1 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nativewind/react-native-css

Tất cả issue của nativewind/react-native-css

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.