react-native-fbads icon indicating copy to clipboard operation
react-native-fbads copied to clipboard

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

Open 123epsilon opened this issue 1 year ago • 5 comments

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.

123epsilon avatar Aug 07 '22 22:08 123epsilon

@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',
]

thejoaov avatar Aug 16 '22 03:08 thejoaov

same problem

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

Anyamborogass avatar Sep 07 '22 08:09 Anyamborogass

'./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 avatar Oct 22 '22 17:10 cbridges1

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

cbridges1 avatar Oct 29 '22 19:10 cbridges1

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

21

chungtv1doi avatar Jan 06 '23 01:01 chungtv1doi