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

Cannot import CSS into html component when serving site as Node.js doesn't understand Webpack module types #83

Closed
esauter5 opened this issue Nov 10, 2015 · 10 comments

Comments

@esauter5
Copy link

First, I apologize if this is due to my own ignorance and not knowing enough about how webpack works, but I cannot seem to load any css files.

In html.jsx I have:

import './css/style.css';

Whenever I run gatsby serve, I get an "Illegal token error" on the css file. I've also seen "Unexpected reserved word" errors where javascript reserved words are used in the CSS (like @import). It doesn't appear that it is recognizing it as a css file, but the webpack loaders look good and I've seen the same thing done in gatsby examples.

Am I missing something obvious here?

@patrykkopycinski
Copy link
Contributor

hi @esauter5 try to require css files instead of importing it, i mean:
require('../css/styles.css');

@esauter5
Copy link
Author

Forgot to mention I had tried that and the same error results so it doesnt seem to be a problem with the import syntax

@KyleAMathews
Copy link
Contributor

This is a non-obvious shortcoming with Gatsby right now that your html file gets loaded in Node not Webpack context which means requiring modules that require Webpack fail.

I experimented with https://github.com/petehunt/webpack-require in the past to solve this but ran into this problem. I haven't tried it recently so it could be working now. @esauter5 if you'd like to experiment with adding webpack-require support into serve.js that'd be a nice fix. I've run into this same problem and had to do weird workarounds.

@KyleAMathews KyleAMathews changed the title Cannot import CSS Cannot import CSS into html component when serving site as Node.js doesn't understand Webpack module types Nov 11, 2015
@esauter5
Copy link
Author

Thanks for the direction @KyleAMathews. I'll play around and see if I can get a PR to submit

@KyleAMathews
Copy link
Contributor

👍🏻
On Tue, Nov 10, 2015 at 6:12 PM Eric Sauter notifications@github.com
wrote:

Thanks for the direction @KyleAMathews https://github.com/KyleAMathews.
I'll play around and see if I can get a PR to submit


Reply to this email directly or view it on GitHub
#83 (comment).

@KyleAMathews
Copy link
Contributor

@esauter5 pushed fix for this using webpack-require. Will be publishing new release soon. Thanks for your patience!

@esauter5
Copy link
Author

Awesome thanks, @KyleAMathews! Sorry I didn't find time to get around to it myself. I worked around it by requiring the css in a different file and then got sidetracked from the project for a bit.

@KyleAMathews
Copy link
Contributor

@esauter5 no worries, I ended up having to do it as part of a bunch of interrelated changes I was making yesterday. Looking forward to other contributions from you ;-)

@esauter5
Copy link
Author

@KyleAMathews Slowly making my way through the code, so I'll eventually start pushing :)

Probably will get in touch with you this week on Reactiflux about some best practices and stuff. Could use some of your Gatsby knowledge.

@KyleAMathews
Copy link
Contributor

👍 feel free. I'm on Discord most of the time.

ChristopherBiscardi added a commit to ChristopherBiscardi/gatsby that referenced this issue Jun 27, 2019
The parent child warnings described in gatsbyjs#83 were the result of us
trying to stuff fileNode into Mdx graphql types. As it turns out, this
is not necessary because you can query the parent using fragments
which more accurately reflect the existence or non-existence of parent
types. This also means you could query the base contentful/remote CMS
types when trying to add slug fields, etc.

Additionally, we unified the code paths that create nodes for all
sources and transformers. Since we now use the public APIs, we can
have more confidence that people can do everything we can in core when
creating new content types.
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this issue Apr 28, 2022
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

3 participants