在我的ReactNative应用程序上安装Realm失败;错误信息如下:npm ERR!在realm@3.6.0的安装脚本'node-pre-gyp install --fallback-to-build'中失败。

3

我正在尝试使用npm为我的React Native应用安装Realm。然而,我无法成功安装。

我的环境/设置如下:

  • Windows 10
  • Node.js v12.13.0
  • npm v6.13.0

我一直尝试用以下命令:
npm install --save realm

或指定版本号:
npm install --save realm@3.6.0

但是完全没有成功的迹象。总是出现以下错误提示但对我来说没有清晰的提示:

> realm@3.6.0 install C:\Projects\<ProjectFolder>\node_modules\realm
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://static.realm.io/node-pre-gyp/3.6.0/realm-v3.6.0-node-v72-win32-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for realm@3.6.0 and node@12.13.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack     at C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:302:5)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\<UserName>\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--fallback-to-build" "--module=C:\\Projects\\<ProjectFolder>\\node_modules\\realm\\compiled\\node-v72_win32_x64\\realm.node" "--module_name=realm" "--module_path=C:\\Projects\\<ProjectFolder>\\node_modules\\realm\\compiled\\node-v72_win32_x64" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
gyp ERR! cwd C:\Projects\<ProjectFolder>\node_modules\realm
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=C:\Projects\<ProjectFolder>\node_modules\realm\compiled\node-v72_win32_x64\realm.node --module_name=realm --module_path=C:\Projects\<ProjectFolder>\node_modules\realm\compiled\node-v72_win32_x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Projects\<ProjectFolder>\node_modules\realm\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Windows_NT 10.0.18362
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Projects\\<ProjectFolder>\\node_modules\\realm\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\Projects\<ProjectFolder>\node_modules\realm
node-pre-gyp ERR! node -v v12.13.0
node-pre-gyp ERR! node-pre-gyp -v v0.13.0
node-pre-gyp ERR! not ok
Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=C:\Projects\<ProjectFolder>\node_modules\realm\compiled\node-v72_win32_x64\realm.node --module_name=realm --module_path=C:\Projects\<ProjectFolder>\node_modules\realm\compiled\node-v72_win32_x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
npm WARN @typescript-eslint/eslint-plugin@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/parser@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of graphql@0.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-sound@^0.10.9 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-voice@^0.2.6 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-elements@0.19.1 requires a peer of react-native-vector-icons@^4.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react@7.12.4 requires a peer of eslint@^3.0.0 || ^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react-native@3.6.0 requires a peer of eslint@^3.17.0 || ^4 || ^5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native@^0.59.5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native-windows@^0.57.2 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! realm@3.6.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the realm@3.6.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<UserName>\AppData\Roaming\npm-cache\_logs\2019-12-21T10_36_02_380Z-debug.log

我按照一篇旧版安装的建议进行了操作:
(即 通过 npm 安装 Realm 时出错:npm ERR!在 realm@1.2.0 安装脚本中失败'node-pre-gyp install --fallback-to-build'
最终成功的版本是 0.x.0 系列(例如 0.14.0),而不是 1.x.x 版本,与最新稳定版本 Realm JavaScript v3.6.0相比要老很多。
这里的讨论与类似错误消息有关,怀疑这是一个 bug:
https://github.com/realm/realm-js/issues/674
https://github.com/realm/realm-js/issues/1924
然后我看到了这个帖子,建议将整个 NodeJS 回滚到 8.x.x 版本以尝试解决问题:
Can not install Realm for my React Native App
这是对于在 Windows 10 环境下开发且安装了 NodeJS v12.13.0 的我来说唯一安装 Realm 到 React Native 应用程序的方式吗?从我发现回滚流程/在不同 NodeJS 版本之间切换过于复杂或只适用于 Mac OS/Linux OS,我担心回滚全局 NodeJS 版本可能会带来其他副作用。
2个回答

10

我已经仔细阅读了Realm在NPM上的详细信息:https://www.npmjs.com/package/realm

其中有一段话表明需要NodeJS的v8或v10版本:

入门指南

请查看我们的文档以获取使用 Realm JavaScript 的详细说明。请注意,目前仅支持 node.js 版本 8 和 10。

因此,我决定不修改全局NPM版本,而是尝试安装一个基于包的Node v10.x.x(即在项目文件夹中运行npm install而不是npm install -g)。然后再次尝试安装Realm。这就像魔法一样奏效了!

所以,我在这里分享步骤,供任何遇到相同情况的人参考:

  1. 进入项目文件夹
  2. 运行npm install node@10.x.x (例如,npm install node@10.17.0
  3. 运行npm install --save realm(或者通过指定版本来安装:npm install --save realm@3.6.0

安装“本地”NodeJS v10的运行结果:

C:\Projects\<ProjectFolder>>npm install node@10.17.0

> node@10.17.0 preinstall C:\Projects\<ProjectFolder>\node_modules\node
> node installArchSpecificPackage

+ node-win-x64@10.17.0
added 1 package in 1.715s
npm WARN @typescript-eslint/eslint-plugin@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/parser@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of graphql@0.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-sound@^0.10.9 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-voice@^0.2.6 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-elements@0.19.1 requires a peer of react-native-vector-icons@^4.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react@7.12.4 requires a peer of eslint@^3.0.0 || ^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react-native@3.6.0 requires a peer of eslint@^3.17.0 || ^4 || ^5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native@^0.59.5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native-windows@^0.57.2 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ node@10.17.0
added 2 packages from 1 contributor and audited 953911 packages in 19.807s

2 packages are looking for funding.
Run "npm fund" to find out more.

安装 Realm 3.6.0 的结果

C:\Projects\<ProjectFolder>>npm install --save realm@3.6.0

> realm@3.6.0 install C:\Projects\<ProjectFolder>\node_modules\realm
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[realm] Success: "C:\Projects\<ProjectFolder>\node_modules\realm\compiled\node-v64_win32_x64\realm.node" is installed via remote
npm WARN @typescript-eslint/eslint-plugin@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/parser@1.13.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of graphql@0.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-sound@^0.10.9 but none is installed. You must install peer dependencies yourself.
npm WARN aws-amplify-react-native@2.2.3 requires a peer of react-native-voice@^0.2.6 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-elements@0.19.1 requires a peer of react-native-vector-icons@^4.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react@7.12.4 requires a peer of eslint@^3.0.0 || ^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react-native@3.6.0 requires a peer of eslint@^3.17.0 || ^4 || ^5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native@^0.59.5 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-fs@2.16.2 requires a peer of react-native-windows@^0.57.2 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ realm@3.6.0
added 62 packages from 32 contributors, removed 1 package and audited 954332 packages in 52.277s

2 packages are looking for funding.
Run "npm fund" to find out more.

1
真的很棒,这是你可以找到的最简单的解决方案,用于这种繁琐的问题。谢谢,它确实非常有效 :) - deeptimancode
你刚刚拯救了我的一天。谢谢。 - Talha Arshad
Node.js在React Native中使用Realm是必需的。我的意思是,我正在使用React代码和MongoDB,所以它是相同的。或者我可以只使用Realm与RN。 - arslan

0

你需要降低你的Node.js版本,无论是全局还是本地,因为目前Realm仅支持Node v8到10,不支持更高版本。所以尝试安装较低版本的Node,例如npm i node@8或10,然后再运行npm i realm --save,这样就可以正常工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接