Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React with NextJS and Next-CSS: You may need an appropriate loader to handle this file type

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?

like image 468
Niklas Avatar asked Sep 27 '18 13:09

Niklas


People also ask

Where do I put CSS Nextjs?

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.

Which CSS framework is best for next JS?

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.

How do I use external CSS in next Javascript?

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.

Does Nextjs have plugins?

Next. js does have plugins that plug into the webpack config (like @next/mdx ).


1 Answers

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());
like image 146
Niklas Avatar answered Oct 23 '22 07:10

Niklas