reactnativecn / react-native-pushy

React Native 极速热更新服务
https://pushy.reactnative.cn
Other
1.77k stars 257 forks source link

pushy bundle --platform android 打热更包时报错:`TypeError: Assignment to constant variable.` (react-native-update-cli\lib\bundle.js bug) #428

Closed coder-xiaomo closed 6 months ago

coder-xiaomo commented 6 months ago

react-native-update-cli 包内代码问题 可将 const 修改为 let

问题代码: C:\Users\Administrator\AppData\Roaming\npm\node_modules\react-native-update-cli\lib\bundle.js

image

完整日志如下:

E:\Project>pushy bundle --platform android
Bundling with react-native:  0.73.5
react-native-update-cli: 1.19.0
react-native-update: 10.1.3
android的crunchPngs选项似乎尚未禁用(如已禁用则请忽略此提示),这可能导致热更包体积异常增大,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96

Running bundle command: node E:\Project\node_modules\react-native\local-cli\cli.js bundle --assets-dest .pushy/intermedia/android --bundle-output .pushy\intermedia\android\index.bundlejs --dev false --entry-file index.js --platform android --reset-cache
warning: the transform cache was reset.

Welcome to Metro v0.80.3
              Fast - Scalable - Integrated

info Writing bundle output to:, .pushy\intermedia\android\index.bundlejs
info Done writing bundle output
info Copying 12 asset files
info Done copying assets
Hermes enabled, now compiling to hermes bytecode:

C:\Users\Coz\AppData\Roaming\npm\node_modules\react-native-update-cli\lib\bundle.js:169
    hermesCommand = fs.existsSync(`${hermesPath}/hermesc`) ? `${hermesPath}/hermesc` // 0.5+
                  ^

TypeError: Assignment to constant variable.
    at compileHermesByteCode (C:\Users\Coz\AppData\Roaming\npm\node_modules\react-native-update-cli\lib\bundle.js:169:19)
    at ChildProcess.<anonymous> (C:\Users\Coz\AppData\Roaming\npm\node_modules\react-native-update-cli\lib\bundle.js:121:17)

Node.js v18.18.0
coder-xiaomo commented 6 months ago

更新到 react-native-update: 10.2.2 依然有此问题,报错日志完全相同:

>pushy bundle --platform android
Bundling with react-native:  0.73.5
react-native-update-cli: 1.19.0
react-native-update: 10.2.2
# 后面输出完全相同

另外感觉这里的判断有些逻辑问题,我这边本地使用的 react-native: 0.73.5 , if (!fs.existsSync(hermesCommand))true,进入了 < rn 0.69 分支

coder-xiaomo commented 6 months ago

@sunnylqm 另外 fs.existsSync(hermesCommand) 这里在 Windows 下会出现问题,

获取到的 hermesCommand: ...\\node_modules\\react-native\\sdks\\hermesc\\win64-bin\\hermesc.exe 👈 这里多 .exe 后缀, fs.existsSync 会找不到该文件

fs.existsSync("...\\node_modules\\react-native\\sdks\\hermesc\\win64-bin\\hermesc.exe")
// true
fs.existsSync("...\\node_modules\\react-native\\sdks\\hermesc\\win64-bin\\hermesc")
// false

image

sunnylqm commented 6 months ago

感谢反馈,我看下

sunnylqm commented 6 months ago

可尝试更新cli到1.20.0版本

coder-xiaomo commented 6 months ago

可尝试更新cli到1.20.0版本

感谢,1.20.0版本已解决此问题😸