1

我正在尝试按照此处的指南将 OneSignal SDK 添加到由 Expo SDK 管理的 ReactNative 项目中:

世博一号信号

这是我在 App.js 中的插件设置

    export default function App() {
  useEffect(() => {
   ///Other things
    OneSignal.setAppId(Constants.manifest.extra.oneSignalAppId);
  }, []);

不幸的是它不起作用,首先我得到:

Invariant Violation: Native module cannot be null.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:204:6 in guardedLoadModule
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:263808:3 in global code

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError

然后,在 GitHub 中打开一个问题后,作者建议我安装:

yarn add react-native-onesignal

这是 Github 上的问题。然后我开始得到:

iOS Bundling failed 3417ms
Unable to resolve module fs from /Users/giulioserra/Documents/App/CTS/node_modules/onesignal-expo-plugin/build/onesignal/withOneSignalIos.js: fs could not be found within the project or in these directories:
  node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  29 | exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
  30 | const config_plugins_1 = require("@expo/config-plugins");
> 31 | const fs = __importStar(require("fs"));

我清除了缓存但什么也没有,这似乎很奇怪,因为据我所知,每个节点版本都应该包含 fs 包,还有建议吗?

4

0 回答 0