Image assets fail to render in Yarn workspace monorepo with React Native 0.81.* and NX
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react-native
- Lĩnh vực
- build-system
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện vấn đề với bố cục Yarn workspace được cung cấp, React Native 0.81.5, NX và cấu hình Metro đã nêu, bằng nx start <project>. So sánh các import asset từ thư mục ứng dụng với các import từ @someWorkspace/assets, và xem xét các issue liên quan 1599 và 1614. Hoàn tất khi các asset hình ảnh từ shared package được resolve và render mà không cần di chuyển chúng vào app.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Image assets fail to render in Yarn workspace monorepo with React Native 0.81.* and NX.
If move assets into application's directory then metro resolves them correctly. But if assets are located in outside application's directory in the monorepo then bundler can not resolve them.
FAILS TO RESOLVE:
repo-root/
├─ apps/
│ └─ someApp/
│ ├─ src/
│ │ └─ App.tsx
│
└─ packages/
└─ assets/ ← asset lives OUTSIDE the app
├─ images/
│ └─ logo.svg
SUCCESSFULLY RESOLVES:
repo-root/
│
├─ apps/
│ └─ someApp/
│ ├─ src/
│ ├─ assets/
│ │ └─ logo.svg ← asset lives INSIDE the app
│ │ └─ App.tsx
│
└─ packages/
Environment
- React Native: 0.81.5
- React: 19.1.0
- Yarn: 4.x (workspaces) and 1.22.22
- Node: 22.x
- OS: macOS 15 (M1 Pro)
- Bundler: Metro (default)
Relevant dependencies
{
"@react-native/metro-config": "0.81.5",
"@react-native/babel-preset": "0.81.5",
"@react-native/typescript-config": "0.81.5",
"react-native-svg-transformer": "1.5.1",
"react-native": "0.81.5",
"react": "19.1.0",
"nx": "21.6.3",
"@nx/react-native": "21.6.3"
}
App usage
// packages/mobile/App.tsx
import React from 'react'
import { Image } from 'react-native'
export const App = () => (
<Image source={require('@someWorkspace/assets/logo.png')} style={{ width: 64, height: 64 }} />
)
When run
nx start <project>
Metro config:
const {withNxMetro} = require('@nx/react-native');
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const {
getMetroAndroidAssetsResolutionFix,
} = require('react-native-monorepo-tools');
const {withDatadogMetroConfig} = require('@datadog/mobile-react-native/metro');
const assetsFix = getMetroAndroidAssetsResolutionFix();
const defaultConfig = getDefaultConfig(__dirname);
const {assetExts, sourceExts} = defaultConfig.resolver;
/**
* Metro configuration
* https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const customConfig = {
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
publicPath: assetsFix.publicPath,
},
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'cjs', 'mjs', 'svg'],
},
server: {
enhanceMiddleware: assetsFix.applyMiddleware,
},
};
module.exports = withNxMetro(
withDatadogMetroConfig(mergeConfig(defaultConfig, customConfig)),
);
NX project config:
{
"name": "projectName",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/someApp/src",
"projectType": "application",
"tags": ["app"],
"targets": {
"start": {
"executor": "@nx/react-native:start",
"dependsOn": ["sync-deps"],
"options": {
"port": 8081,
"resetCache": true
}
}
}
...Other config
}
The app builds and runs, but the image renders as an empty space.
Expected behavior
Metro/React Native should correctly resolve and bundle static image assets exported from shared workspace packages — the same way it handles JS modules.
Actual behavior
When importing images from another workspace (e.g., @someWorkspace/assets), the app runs without any build or runtime error, but the image simply does not appear.
Screenshots / recordings
Related issues:
Additional info:
Possible fixes from above issues didn't work out.
- Ngôn ngữ chính
- JavaScript
- Star
- 5.6k
- Fork
- 702
- Merge trung bình
- 3 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 50
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của react/metro
-
constant-folding-plugin emits 0/0 (NaN) for arithmetic on destructured bindingsCó thể đã có người làm @cpruijsen đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
react/metro#1927 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[0.83.x] Backport micromatch removal and dotfile/multipart watcher fix togetherCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`dependencies is not iterable` / `Cannot read property 'reduce' of undefined`: `FileStore` serves zero-prefixed cache files as hitsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
react/metro#1961 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Async chunk URLs drop the file extension, so .cjs async imports fail with "Requiring unknown module"Có thể đã có người làm @dasjideepak đã nhận 14 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
react/metro#1959 · 2 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Files changed during startup can be missed until restartCó thể đã có người làm @cpruijsen đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
ACK_WAITING HELP_WANTED UPDATE_CS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OWASP/CheatSheetSeries#2781 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hermes: /ponytail off never reaches the model, the ruleset stays activeCó thể đã có người làm @szsunyuan đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DietrichGebert/ponytail#1121 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
integrations plugin
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
mem0ai/mem0#7622 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug package:vitest
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
cloudflare/workers-sdk#16238 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày