To building a React-App i using NextJS. To use a css-file, i use the next-css plugin
to do that. But when i build my App, i get the following error:
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
My next.config.js
file, looks like this:
// next.config.js
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
cssModules: false,
})
I importe and use a .css-file in my components as follows:
import '../style.css'
export default () => <div className="example">Hello World!</div>
My css-file Looks like this:
.example {
color: red;
}
Where is my issue? Can anyone help me to fix that?
Adding a Global Stylesheet To add a stylesheet to your application, import the CSS file within pages/_app.js . Create a pages/_app.js file if not already present. Then, import the styles.css file. These styles ( styles.css ) will apply to all pages and components in your application.
Tailwind CSS is one of the most famous CSS frameworks out there and is especially used with React. js and Next. js. It is a utility-first CSS framework packed with classes like flex flex-start pt-4 items-center that can be composed to build any design, directly in your markup.
You can add the css file in head of nextjs. and in the render method, inside the return add a head tag similar to ordinary HTML, the head tag should be inside a div. also the css should be in static folder. Add a key to the link tag to reuse the css in multiple pages.
Next. js does have plugins that plug into the webpack config (like @next/mdx ).
I solved the problem. In my next.config.js
i use multiple plugins. My mistake was that I had written several module.exports
statements. In my case, the solution looks like this:
//next.config.js
const withImages = require('next-images');
const withCSS = require('@zeit/next-css');
module.exports = withImages(withCSS());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With