英文:
React Native build is failing
问题
我正在尝试按照这个指南创建一个 React Native for Windows 项目:
https://microsoft.github.io/react-native-windows/docs/getting-started
当我尝试使用 npx react-native run-windows
运行我的应用程序时,我收到以下错误消息:
生成成功。
0 个警告
0 个错误
用时 00:00:01.34
√ 恢复 NuGet 包
√ 自动链接...
成功:不需要进行自动链接更改。(7毫秒)
√ 找到解决方案:C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN.sln
i 生成配置:Debug
i 生成平台:x64
× 生成解决方案:C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-...
× 生成失败,错误消息为 5:6>C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-windows\PropertySheets\ManagedCodeGen\Microsoft.ReactNative.Managed.CodeGen.targets(78,5): error MSB3073: 命令“C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-windows\target\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\publish\Microsoft.ReactNative.Managed.CodeGen.exe @C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN\obj\x64\Debug\SparrowRN.ReactNativeCodeGenSparrowRN.ReactNativeCodeGen.rsp”退出,代码为 9009。[C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN\SparrowRN.csproj]。请检查您的生成配置。
命令失败。使用 --logging 重新运行命令以获取更多信息。
我尝试在 PowerShell 中运行以下命令:
Set-ExecutionPolicy Unrestricted -Scope Process -Force;
iex (New-Object System.Net.WebClient).DownloadString('https://aka.ms/rnw-vs2022-deps.ps1');
看起来我没有缺少的依赖项。有什么建议吗?
注意:我没有完全按照指南操作。我在 npx react-native-windows-init --overwrite
中添加了 --language=cs
。
英文:
I'm trying to create a React Native for Windows project by following this guide:
https://microsoft.github.io/react-native-windows/docs/getting-started
When I try to run my app using npx react-native run-windows
I get this error:
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.34
√ Restoring NuGet packages
√ Auto-linking...
Success: No auto-linking changes necessary. (7ms)
√ Found Solution: C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN.sln
i Build configuration: Debug
i Build platform: x64
× Building Solution: C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-...
× Build failed with message 5:6>C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-windows\PropertySheets\ManagedCodeGen\Microsoft.ReactNative.Managed.CodeGen.targets(78,5): error MSB3073: The command "C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\node_modules\react-native-windows\target\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\publish\Microsoft.ReactNative.Managed.CodeGen.exe @C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN\obj\x64\Debug\SparrowRN.ReactNativeCodeGenSparrowRN.ReactNativeCodeGen.rsp" exited with code 9009. [C:\Users\alial\OneDrive\Desktop\Workshop\Visual Studio\SparrowRN\windows\SparrowRN\SparrowRN.csproj]. Check your build configuration.
Command failed. Re-run the command with --logging for more information.
I tried running this command in powershell:
Set-ExecutionPolicy Unrestricted -Scope Process -Force;
iex (New-Object System.Net.WebClient).DownloadString('https://aka.ms/rnw-vs2022-deps.ps1');
and it seems that I don't have any missing dependencies. Any suggestions?
Note: I did not follow the guid exactly. I added --language=cs
to npx react-native-windows-init --overwrite
.
答案1
得分: 2
出现的错误消息表明您的React Native for Windows项目存在构建配置问题或缺少依赖项。以下是一些建议来解决这个问题:
验证构建配置:
请再次确认您的构建配置是否设置正确。确保您正在使用所需的配置(例如,Debug或Release)和平台(例如,x64或ARM)构建项目。您可以在Visual Studio解决方案中验证并更改这些设置。
更新依赖项:
确保您拥有所有必需依赖项的最新版本。尝试运行以下命令以更新项目的依赖项:
npm install react-native-windows@latest
清理和重新构建:
清理项目的构建输出,然后重新构建它。您可以在Visual Studio中执行此操作,或者在项目目录中运行以下命令:
npx react-native-windows-clean
npx react-native run-windows
检查MSBuild工具:
确认您的计算机上已安装必要的MSBuild工具。React Native for Windows文档提供了所需工具及其版本的列表。确保您已安装了正确版本或更新版本。
更新React Native CLI:
确保您正在使用React Native CLI的最新版本。您可以通过运行以下命令全局更新它:
npm install -g react-native-cli
删除并重新安装Node模块:
有时由于已安装的Node模块中的冲突或损坏,可能会出现问题。尝试删除node_modules文件夹并重新安装依赖项:
rm -rf node_modules
npm install
按照指南:
尽管您提到没有完全按照指南操作,但通常建议密切遵循官方文档和设置说明。确保您没有错过任何关键步骤或项目特定的修改。
如果上述解决方案都无法解决问题,可能有必要提供更多关于项目设置和配置的上下文或具体细节。此外,您可以尝试在React Native for Windows GitHub存储库上搜索类似的问题,或在那里发布问题以获取进一步的帮助。
英文:
The error message you're encountering suggests that there is an issue with the build configuration or a missing dependency in your React Native for Windows project. Here are a few suggestions to troubleshoot this problem:
Verify Build Configuration:
Double-check that your build configuration is set correctly. Make sure you are building the project in the desired configuration (e.g., Debug or Release) and platform (e.g., x64 or ARM). You can verify and change these settings in your Visual Studio solution.
Update Dependencies:
Ensure that you have the latest versions of all required dependencies. Try running the following command to update your project's dependencies:
npm install react-native-windows@latest
Clean and Rebuild:
Clean your project's build output and then rebuild it. You can do this from within Visual Studio or by running the following command in the project directory:
npx react-native-windows-clean
npx react-native run-windows
Check MSBuild Tools:
Confirm that you have the necessary MSBuild tools installed on your machine. The React Native for Windows documentation provides a list of required tools and their versions. Ensure that you have installed the correct versions or newer.
Update React Native CLI:
Ensure that you are using the latest version of the React Native CLI. You can update it globally by running:
npm install -g react-native-cli
Remove and Reinstall Node Modules:
Sometimes issues can arise due to conflicts or corruption in the installed node modules. Try removing the node_modules folder and reinstalling the dependencies:
rm -rf node_modules
npm install
Follow the Guide:
Although you mentioned not following the guide exactly, it's generally recommended to follow the official documentation and setup instructions closely. Ensure that you haven't missed any crucial steps or modifications specific to your project.
If none of the above solutions resolve the issue, it might be helpful to provide more context or specific details about your project setup and configuration. Additionally, you can try searching for similar issues on the React Native for Windows GitHub repository or posting a question there for further assistance.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论