Skip to content

Failing next.js build since 1.1.0: ModuleParseError: Module parse failed: Unexpected character #28

@sesigl

Description

@sesigl

Hey,

I use custom css next.js setup to enable 3rd party dependencies to include css. Since 1.1.0 my build is failing with:

Failed to compile.
18:00:37.456  ./node_modules/react-multi-carousel/lib/styles.css
18:00:37.456  ModuleParseError: Module parse failed: Unexpected character '' (1:0)
18:00:37.457  You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
18:00:37.457  (Source code omitted for this binary file)
18:00:37.458  > Build error occurred
18:00:37.459  Error: > Build failed because of webpack errors
18:00:37.459      at build (/zeit/6b3a4e9a/node_modules/next/dist/build/index.js:13:900)

my next.conf.js:

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

const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

const nextConfig = {
  env: {
    GOOGLE_API_KEY: 'SOME_KEY',
    REACT_APP_GOOGLE_MAP_API_KEY:
      'SOME_OTHER_KEY',
  },
  webpack: (config, { isServer }) => {
    if (isServer) {
      const antStyles = /antd\/.*?\/style\/css.*?/;
      const origExternals = [...config.externals];
      config.externals = [
        (context, request, callback) => {
          if (request.match(antStyles)) return callback();
          if (typeof origExternals[0] === 'function') {
            origExternals[0](context, request, callback);
          } else {
            callback();
          }
        },
        ...(typeof origExternals[0] === 'function' ? [] : origExternals),
      ];

      config.module.rules.unshift({
        test: antStyles,
        use: 'null-loader',
      });
    }
    //   // HOTFIX: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/250
    config.plugins.push(
        new FilterWarningsPlugin({
          exclude: /mini-css-extract-plugin[^]*Conflicting order between:/,
        })
    );

    config.resolve.modules.push(__dirname);

    config.plugins.push(new webpack.IgnorePlugin(/(.*)(test|spec)\.(ts|js|tsx|jsx)$/));

    return config;
  },
};

module.exports = withPlugins(
  [
    [
      withOptimizedImages,
      {
        mozjpeg: {
          quality: 90,
        },
        webp: {
          preset: 'default',
          quality: 90,
        },
      },
    ],
    withFonts,
    withCSS,
  ],
  nextConfig
);

If I downgrade to 1.0.3, then everything is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions