Metro 捆绑器可以解析依赖关系图(应用程序在模拟器中启动),但无法解析任何资产,因此应用程序中的所有图像都丢失了。
只有在我从 react-native@0.57 升级到 0.59 后才会出现此问题
Looking for JS files in
/Users/name/app/MyApp/artifacts
/Users/name/app/MyApp/node_modules
warning: the transform cache was reset.
Loading dependency graph, done.
DELTA [android, dev] artifacts/index.js ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100.0% (2921/2921), done.
MAP [android, dev] artifacts/index.js ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100.0% (1/1), done.
::ffff:127.0.0.1 - - [30/Aug/2019:06:27:17 +0000] "GET /node_modules/my-assets/artifacts/assets/images/Logo.png?platform=android&hash=someHash HTTP/1.1" 404 221 "-" "okhttp/3.12.1"
^^^ 问题出现在导航到包含<Image source=... />
该模块my-assets
确实存在并包含所需的所有资产
开始:node node_modules/react-native/local-cli/cli.js start --reset-cache --projectRoot artifacts
artifacts
包含.js
从_.ts
我的文件结构看起来像这样
.
├── artifacts # transpiled js files
├── node_modules #npm modules
└── src # ts files
捆绑器服务器输出
Metro.config.js
module.exports = {
watchFolders: [path.join(__dirname, 'node_modules')],
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
},
resolver: {
blacklistRE: blacklist([ /node_modules\/.*\/node_modules\/react-native\/.*/]),
assetRegistryPath: path.resolve('node_modules/react-native/Libraries/Image/AssetRegistry')
}
}
依赖项:
my-app@1.0 /Users/name/app/MyApp
├── metro@0.48.5 extraneous
└─┬ react-native@0.59.4
└─┬ @react-native-community/cli@1.11.2
├── metro@0.51.1
└─┬ metro-config@0.51.1
└── metro@0.51.1 deduped
我还尝试在浏览器中转到 url,但也为以下两个请求转到 404
http://localhost:8081/node_modules/my-assets/artifacts/assets/images/Logo.png?platform=android&hash=someHash
http://localhost:8081/node_modules/metro/src/Bundler/util.js # request to any js file also return 404
- 更新 -
清理缓存和删除 $TMPDIR 无济于事