Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to resolve plugin for module "react-native-fbads" relative to [project dir] #333

Open
123epsilon opened this issue Aug 7, 2022 · 5 comments

Comments

@123epsilon
Copy link

Bug Report

Before opening

  • [ X] Did you try the latest release?
  • [ X] Did you look for existing issues?

Ad Modules

Have this activated in my facebook app

Platforms

Developing for both android and ios

Versions

  • react-native-fbads: 7.1.0
  • react-native: 0.68.2

I am using an eas build for a project that is part of a managed expo workflow. I followed the instructions under "expo installation" in the main readme. When I attempt to run eas build --profile development --platform ios I get the following cryptic error:

Failed to resolve plugin for module "react-native-fbads" relative to "D:\Projects\pollenbbmap"

My app.json looks like this

{
  "expo": {
    "owner": "gainesvilleboyz",
    "name": "pollenbbmap",
    "slug": "pollenbbmap",
    "version": "0.0.1",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.arham23.pollenbbmap"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      [
        "react-native-fbsdk-next",
        {
          "appID": "XXXX",
          "clientToken": "XXX",
          "displayName": "Pollen Map App",
          "advertiserIDCollectionEnabled": false,
          "autoLogAppEventsEnabled": false,
          "isAutoInitEnabled": true,
          "iosUserTrackingPermission": "This identifier will be used to deliver personalized ads to you."
        }
      ],
      "react-native-fbads"
    ]
  }
}

Has anyone else experienced this error? Google shows zero results with this issue.

@thejoaov
Copy link

thejoaov commented Aug 16, 2022

@123epsilon
For me, it worked when I created a file react-native-fbads.js, with

const {
  AndroidConfig,
  createRunOncePlugin,
  withAndroidManifest,
} = require('@expo/config-plugins');

const { getMainApplicationOrThrow, prefixAndroidKeys } = AndroidConfig.Manifest;

const INTERSTITIAL_AD_ACTIVITY = 'com.facebook.ads.InterstitialAdActivity';

const withFacebookManifest = (config) => {
  return withAndroidManifest(config, (config) => {
    config.modResults = setFacebookConfig(config.modResults);
    return config;
  });
};

function setFacebookConfig(androidManifest) {
  let mainApplication = getMainApplicationOrThrow(androidManifest);
  mainApplication = ensureFacebookActivity({ mainApplication });

  return androidManifest;
}

function ensureFacebookActivity({ mainApplication }) {
  if (Array.isArray(mainApplication.activity)) {
    // Remove all Facebook InterstitialAdActivity first
    mainApplication.activity = mainApplication.activity.filter((activity) => {
      return activity.$?.['android:name'] !== INTERSTITIAL_AD_ACTIVITY;
    });
  } else {
    mainApplication.activity = [];
  }

  mainApplication.activity.push(getFacebookAdActivity());
  return mainApplication;
}

function buildXMLItem({ head, children }) {
  return { ...(children ?? {}), $: head };
}

function getFacebookAdActivity() {
  /**
<activity
  android:name="com.facebook.ads.InterstitialAdActivity"
  android:configChanges="keyboardHidden|orientation"
/>
   */
  return buildXMLItem({
    head: prefixAndroidKeys({
      name: INTERSTITIAL_AD_ACTIVITY,
      configChanges: 'keyboardHidden|orientation',
    }),
  });
}

/**
 * Apply react-native-fbads configuration for Expo SDK 44 projects.
 */
const withReactNativeFbads = (config) => {
  return withFacebookManifest(config);
};

const pkg = require('../../node_modules/react-native-fbads/package.json');

module.exports = {
  withFacebookManifest,
  setFacebookConfig,
  default: createRunOncePlugin(withReactNativeFbads, pkg.name, pkg.version),
};

and on my app.config.ts I used on the plugins array like that:

plugins: [
        // ......
        './react-native-fbads.js',
]

@Anyamborogass
Copy link

Anyamborogass commented Sep 7, 2022

same problem

PluginError: Failed to resolve plugin for module "react-native-fbads" relative to "D:\Projects\myApp"
Code: PLUGIN_NOT_FOUND

@cbridges1
Copy link

'./react-native-fbads.js',
This definitely works but I'm not sure this will be an optimal solution. Shouldn't EAS recognize the plugin file that is in node_modules? This is my first time creating a custom dev build for expo so I'm not 100% of the process.

@cbridges1
Copy link

It looks like there is no dist folder for this package. The package.json file is looking for a reference that does not exist in the node_modules directory.

image

@chungtv1doi
Copy link

Hi Freind
I run React-native -cli and also cope this problem. How to fix it?

21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants