question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module parse failed: Unexpected character '�' (1:0)

See original GitHub issue

I’m getthing this error for both dev & prod builds, for all image file types:

Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)

I’ve tried reinstalling dependency packages. Also tried to configure next config with and without next-compose-plugins but same result. My current config:

const webpack = require('webpack');
const sass = require('@zeit/next-sass');
const CSS = require('@zeit/next-css')
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const fonts = require('next-fonts');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

const nextConfig = {
  serverRuntimeConfig: { // Will only be available on the server side
    
  },
  publicRuntimeConfig: { // Will be available on both server and client
    DOMAIN: process.env.NODE_ENV == 'production' ? 'https://www.example.com/wordpress/index.php' : 'http://example.dev',
  }
}

module.exports = withPlugins([
  [optimizedImages, {
    optimizeImagesInDev: true
  }
  ],
  [sass({
    webpack(config, options) {
      config.module.rules.push({
        test: /\.(raw)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: 'raw-loader',
      });
      if (config.mode === 'production') {
        if (Array.isArray(config.optimization.minimizer)) {
          config.optimization.minimizer.push(new OptimizeCSSAssetsPlugin({}));
        }
      }
      return config;
    }
  })],
  [CSS],
  [fonts]

  // your other plugins here
 
], nextConfig);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14

github_iconTop GitHub Comments

17reactions
gisetecommented, Jul 16, 2019

@geochanto I was! I still get the warnings in dev but no warnings in prod anymore. In my case too I was getting a not found error message for the optimized assets but I think it got fixed after I deleted package-lock.json and the node-modules folder and re-installed everything but I think you already tried that too right?

In case it helps here’s my next config now:

const webpack = require('webpack')
const withCSS = require('@zeit/next-css')
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const path = require('path');
const isDevelopment = process.env.NODE_ENV === 'development'
const isProduction = process.env.NODE_ENV === 'production';

const nextConfig = {
    webpack: (config, { dev }) => {
        config.plugins.push(
            new webpack.EnvironmentPlugin(process.env),
        );
        
        config.resolve.alias['components'] = path.join(__dirname, 'components')
        config.resolve.alias['static'] = path.join(__dirname, 'static')

        return config;
    },
};

module.exports = withPlugins([
    [optimizedImages, {
        handleImages: ['jpeg', 'png'],
    }],
    withCSS
    ],
    nextConfig
);
4reactions
gisetecommented, Jul 15, 2019

Just narrowed down what’s works vs what doesn’t. Looks like I start getting this error when I add config options.

This doesn’t work:

const withCSS = require('@zeit/next-css')
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const path = require('path');

module.exports = withPlugins([
    [ optimizedImages, {
            imagesOutputPath: 'static/',
            handleImages: ['jpeg', 'png'],
    }]
    ],
{
    webpack: (config, { dev }) => {
        config.plugins.push(
            new webpack.EnvironmentPlugin(process.env),
        );
        
        // Config to have absolute imports instead of relative imports 
        config.resolve.alias['components'] = path.join(__dirname, 'components')
        config.resolve.alias['static'] = path.join(__dirname, 'static')

        return config;
    },
});

This works:

const webpack = require('webpack')
const withCSS = require('@zeit/next-css')
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const path = require('path');

module.exports = withPlugins([
        optimizedImages
    ],
{
    webpack: (config, { dev }) => {
        config.plugins.push(
            new webpack.EnvironmentPlugin(process.env),
        );
        
        // Config to have absolute imports instead of relative imports 
        config.resolve.alias['components'] = path.join(__dirname, 'components')
        config.resolve.alias['static'] = path.join(__dirname, 'static')

        return config;
    },
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 4 - Module parse failed: Unexpected character '@'
It's now throwing an error: Module parse failed: Unexpected character '@' You may need an appropriate loader to handle this file type.
Read more >
Does not resolve @import. Module parse failed: Unexpected ...
The loader can't resolve @imports, throws error. Config file is just fine, but sass-loader throws errors anyhow: ERROR in .
Read more >
Can't build with webpack - Material Design for Bootstrap
css 1:0 Module parse failed: Unexpected character '@' (1:0) You may need an appropriate loader to handle this file type, currently no loaders...
Read more >
Module parse failed: Unexpected character ' ' (1:0) You may ...
[Solved]-Module parse failed: Unexpected character ' ' (1:0) You may need an appropriate loader to handle this file type-Reactjs · Related Query ·...
Read more >
Import css module - sage - Roots Discourse
yarn dev yarn run v1.22.17 $ bud dev ✘ Module parse failed: Unexpected character '@' (13:0) You may need an appropriate loader to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found