提问人:morganTrudeau 提问时间:1/20/2023 最后编辑:morganTrudeau 更新时间:1/21/2023 访问量:178
由于 react-native-reanimated babel 插件,无法应用源映射
Source map can't be applied due to react-native-reanimated babel plugin
问:
我看到的是添加 react-native-reanimated babel 插件 (react-native-reanimated/plugin) 导致捆绑时源映射无效。我正在使用 Bugsnag,它说我的源映射与我的代码不匹配。
还有其他人使用 reanimated 2 并遇到这种情况吗?有没有人对此有任何解决方法的建议?因此,我无法解决 Bugsnag 上报告的一些错误。
感谢您的帮助!
我使用 npm 包 sourcemap-validator 验证了源映射,它确实抛出了一个错误,说源映射与捆绑包不匹配。
我用一个新的 react-native init 项目重现了这一点。此错误发生在我使用 react-native 0.66.4 的项目和使用 react-native 0.70.6 的示例应用程序中
示例应用 https://github.com/MorganTrudeau/rn-sample
存储库中有一个 README,其中包含重现无效源映射的步骤。
简短解释我为验证地图源映射所做的工作,以及为什么我认为它是复活的 babel 插件。
验证 sourcemap 的步骤
所有这些代码都在上面提供的存储库中,以测试自己。
// babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['react-native-reanimated/plugin'],
};
// Create the bundle and sourcemap
npx react-native bundle --platform android --dev false --entry-file index.js --reset-cache --bundle-output index.android.bundle --sourcemap-output index.android.bundle.map --minify false
// validate_sourcemap.js
// Sourcemap validation code using sourcemap-validator library
var validate = require('sourcemap-validator'),
fs = require('fs'),
assert = require('assert'),
min = fs.readFileSync('index.android.bundle', 'utf-8'),
map = fs.readFileSync('index.android.bundle.map', 'utf-8');
assert.doesNotThrow(function () {
validate(min, map);
}, 'The sourcemap is not valid');
console.log('Valid source map');
上述验证失败,并显示 。如果删除 and 重新捆绑并再次运行验证,则验证会通过。react-native-reanimated/plugin
react-native-reanimated/plugin
我已经在一个新的 react-native init 项目上进行了测试。我假设这就是为什么我的源图无法在 Bugsnag 上工作的原因。
谢谢。
答: 暂无答案
评论