react-places-autocomplete: Powered By Google not being imported - Require Cannot find module

Hello, I get this error since lastest release 5.4.0, please help !

Uncaught Error: Cannot find module 'react-places-autocomplete/images/powered_by_google_default.png' from 'react-places-autocomplete/dist/PlacesAutocomplete.js'

Line 372 of /node_modules/react-places-autocomplete/dist/PlacesAutocomplete.js is generating the error. this.props.googleLogo && _react2.default.createElement( 'div', { id: 'PlacesAutocomplete__google-logo', style: this.inlineStyleFor('googleLogoContainer'), className: this.classNameFor('googleLogoContainer') }, _react2.default.createElement('img', { src: require('./images/powered_by_google_' + this.props.googleLogoType + '.png'), style: this.inlineStyleFor('googleLogoImage'), className: this.classNameFor('googleLogoImage') }) )

When using hard coded path of copy of the image from my assets/images folder works perfectly. E.g. src: “http://localhost:4000/images/powered_by_google_default.png

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 23 (7 by maintainers)

Most upvoted comments

Expanding on @Floriferous 's solution, this is a quick workaround that I am using until something more permanent is implemented into the package.

const myStyles = {
    autocompleteContainer: {
        paddingBottom: '20px',
        backgroundSize: 'auto 12px',
        backgroundPosition: 'bottom left 10px',
        backgroundRepeat: 'no-repeat',
        backgroundImage: "url('https://maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white3_hdpi.png')",
    },
};
<PlacesAutocomplete
    styles={myStyles}
    googleLogo={false}
/>

You lose some semantics this way (by not having an inline image) but seems like a decent work around in the short time that could come in handy for some.

Would it make sense to remove Google Image from the library and add an optional footer prop so that user of the library can provide their custom footer element for the dropdown? Feedback would be appreciated!

@kenny-hibino forgot to mention, I am using brunch on phoenixframework. Could that be where my issue is coming from ?

brunch-config.js

exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    javascripts: {
      joinTo: "js/app.js"
    },
    stylesheets: {
      joinTo: "css/app.css",
      order: {
        before: [
        "css/vendor/foundation.min.css",
        "css/vendor/react-datepicker-cssmodules.min.css",
        "css/vendor/react-datepicker.min.css",
        "css/vendor/rc-slider.css"
        ]
      }
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    // This option sets where we should place non-css and non-js assets in.
    // By default, we set this to "/assets/static". Files in this directory
    // will be copied to `paths.public`, which is "priv/static" by default.
    assets: /^(static)/
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: ["static", "css", "js", "vendor"],
    // Where to compile files to
    public: "../priv/static"
  },

  // Configure your plugins
  plugins: {
    babel: {
      presets: ["es2015", "react"],
      // Do not use ES6 compiler in vendor code
      ignore: [/web\/static\/vendor/]
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["js/app"]
    }
  },

  npm: {
    enabled: true,
    whitelist: ["phoenix", "phoenix_html", "react", "react-dom"]
  }
}

Only thing that works for me is locking the version to 5.3.1 "react-places-autocomplete": "5.3.1",

The answer is to add url-loader in your project package.json.

I just added the package and it work fine.

I think it’s better to specify it in this project package.json if possible because in my case I do not use url-loader