Gatsby: What's a good way to include an external JS file?

Created on 25 Feb 2017  路  6Comments  路  Source: gatsbyjs/gatsby

Trying to add this: https://github.com/rishabhp/bideo.js (which has no npm module)
Where do I put it so it gets bundled?

All 6 comments

Just require it. It doesn't look like it has any exports so copy it into your site and require it into your _template.js

Could you give an example? I'm just getting Module not found: Error: Cannot resolve module 'bideo'. Is this because it doesn't export anything?

Nvm, I got it. Thank you @KyleAMathews.

Hi @ivanakimov how did you do it?
I'm trying to reference google place api

 Autocomplete = require("https://maps.googleapis.com/maps/api/js?key=MY_API&libraries=places&callback=initAutocomplete");

        autocomplete = new this.Autocomplete(
            /** @type {!HTMLInputElement} */this.searchTextBox,
            {types: ['geocode']});

but got an error:

Module not found: Error: Cannot resolve module 'https://maps.googleapis.com/maps/api/js' in my jsx file

Please help~!

@franva this is not the same thing. I was requiring a file within my own project. If you want to include the Google Maps API, you're gonna have to use a <script> tag: https://developers.google.com/maps/documentation/javascript/examples/map-simple

Hi @ivanakimov I tried that way as well, but no luck. Here is my question:
https://stackoverflow.com/questions/50274502/load-google-place-api-in-gatsbyjs-reactjs-project

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonmp picture brandonmp  路  3Comments

andykais picture andykais  路  3Comments

hobochild picture hobochild  路  3Comments

kalinchernev picture kalinchernev  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments