Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Having trouble importing script #73

Open
jskrt opened this issue Jun 26, 2018 · 4 comments
Open

Having trouble importing script #73

jskrt opened this issue Jun 26, 2018 · 4 comments

Comments

@jskrt
Copy link

jskrt commented Jun 26, 2018

I'm trying to use frosted-glass in a project I am working on but I am having trouble loading the script. I am using GatsbyJS to set up my project and loading the script through React Helmet in my index.js file. I installed the frosted-glass package as described in the README. It is sitting in node_modules but somehow I am running into this error:

GET http://localhost:8000/node_modules/frosted-glass/dist/frostedglass.js 404 (Not Found)

Here is what my React Helmet code looks like:

const Layout = ({ children, data }) => (
  <div>
    <Helmet>
      <title>{data.site.siteMetadata.title}</title>
      <meta name='description' content='Sample'/>
      <meta name='keywords' content='sample, something' />
      <meta name='viewport' content='width=device-width, initial-scale=1'/>
      <script src="/node_modules/frosted-glass/dist/frostedglass.js" type="text/javascript" />
    </Helmet>
    <div>
      {children()}
    </div>
  </div>
)

If I just write src="node_modules/frosted-glass/dist/frostedglass.js", it still gives me the same error but this time, looks inside http://localhost:8000/about/ or whatever the current page is.

I tried to use require as well, removing the script tag in React Helmet:

const FrostedGlass = require('frosted-glass/dist/frostedglass.js');

but I get the following error:

GET http://localhost:8000/frostedglass/frostedglass.pxrm46tt.js 404 (Not Found)

I'm not sure if this is happening because of Gatsby or not. Any ideas?

@libertyswift
Copy link

Yes, I have the same error when connecting script via webpack import 'frosted-glass'
This works only if you connect a script via <script src='https://unpkg.com/frosted-glass/dist/frostedglass.js'></script>

@jskrt
Copy link
Author

jskrt commented Jul 1, 2018

It's still not finding the resource. I went to the example CodePen and forked it and it isn't finding the resource in the forked pen either.

@jskrt
Copy link
Author

jskrt commented Jul 9, 2018

@adriancarriger any ideas?

@adriancarriger
Copy link
Owner

Hi @jskrt, it sounds like you may be using Webpack. If so, you'd probably like the NPM module @stencil/webpack (here's a quick tutorial).

Another quick option would be to add the import script directly to your index.html like this.

Let me know how it goes 👍

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

No branches or pull requests

3 participants