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

hot-reloader with stylelint-webpack-plugin causes unhandled exception #3560

Closed
1 task done
bryan opened this issue Jan 10, 2018 · 3 comments
Closed
1 task done

hot-reloader with stylelint-webpack-plugin causes unhandled exception #3560

bryan opened this issue Jan 10, 2018 · 3 comments

Comments

@bryan
Copy link

bryan commented Jan 10, 2018

  • I have searched the issues of this repository and believe that this is not a duplicate.
(node:30515) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'reasons' of undefined
    at /Users/project/node_modules/next/dist/server/hot-reloader.js:445:37
    at Array.map (<anonymous>)
    at Compiler.<anonymous> (/Users/project/node_modules/next/dist/server/hot-reloader.js:444:79)
    at Compiler.applyPlugins (/Users/project/node_modules/tapable/lib/Tapable.js:61:14)
    at Watching._done (/Users/project/node_modules/next/node_modules/webpack/lib/Compiler.js:104:17)
    at compiler.emitRecords.err (/Users/project/node_modules/next/node_modules/webpack/lib/Compiler.js:78:19)
    at Compiler.emitRecords (/Users/project/node_modules/next/node_modules/webpack/lib/Compiler.js:375:38)
    at compiler.emitAssets.err (/Users/project/node_modules/next/node_modules/webpack/lib/Compiler.js:61:20)
    at applyPluginsAsyncSeries1.err (/Users/project/node_modules/next/node_modules/webpack/lib/Compiler.js:368:12)
    at next (/Users/project/node_modules/tapable/lib/Tapable.js:218:11)
    at Compiler.afterEmit (/Users/project/node_modules/stylelint-webpack-plugin/lib/run-compilation.js:52:5)
    at next (/Users/project/node_modules/tapable/lib/Tapable.js:220:14)
    at Compiler.<anonymous> (/Users/project/node_modules/next/dist/server/hot-reloader.js:432:19)
    at next (/Users/project/node_modules/tapable/lib/Tapable.js:220:14)
    at Compiler.compiler.plugin (/Users/project/node_modules/next/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at next (/Users/project/node_modules/tapable/lib/Tapable.js:220:14)
    at /Users/project/node_modules/next/dist/server/build/plugins/unlink-file-plugin.js:98:18
    at <anonymous>
(node:30515) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:30515) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected Behavior

stylelint-webpack-plugin should work with webpack config defined in next.config.js

Current Behavior

The stylelint-webpack-plugin complains about an uncaught property 'reasons' and displays the initial linting warnings/errors. Not working for subsequent reloads as a result

Steps to Reproduce (for bugs)

  1. Install stylelint, stylelint-webpack-plugin
  2. Configure StyleLintPlugin in next.config.js
  3. Run program and observe error after webpack config is loaded in

Context

Linting usage for dev purposes

Your Environment

Tech Version
next 5.0.0
node 9.4.0
OS macos
@lededje
Copy link

lededje commented Jan 11, 2018

Can you post your next.config.js so we can reproduce this issue?

@bryan
Copy link
Author

bryan commented Jan 11, 2018

Here you go.

const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const withCSS = require('@zeit/next-css');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');

module.exports = withCSS({
  poweredByHeader: false,
  webpack: (config, options) => {
    const {dev, isServer} = options;

    config.plugins.push(
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
      }),
      new UglifyJsPlugin({
        test: /\.js($|\?)/i
      }),
      new StyleLintPlugin({
        configFile: path.resolve(__dirname, './.stylelintrc'),
        context: 'css',
        failOnError: false,
      }),
    );

    config.module.rules.push(
      {
        test: /\.(css|scss)/,
        loader: 'emit-file-loader',
        options: {
          name: 'dist/[path][name].[ext]'
        }
      },
      {
        test: /\.s(a|c)ss$/,
        exclude: /node_modules/,
        use: ['babel-loader', 'raw-loader', 'postcss-loader',
          { loader: 'sass-loader',
            options: {
              includePaths: ['styles', 'node_modules']
                .map((d) => path.join(__dirname, d))
                .map((g) => glob.sync(g))
                .reduce((a, c) => a.concat(c), [])
            }
          }
        ],
      },
      {
        test: /\.js$/,
        enforce: 'pre',
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: {
          emitWarning: dev,
        },
      }
    )

    return config;
  },
});

@bryan
Copy link
Author

bryan commented Feb 6, 2018

@timneutkens Still running into the hot-reloader error after upgrade to v5.0, any idea?

https://github.com/zeit/next.js/blob/7a1d9c18a39860f5711446595543468bfbdef04e/server/hot-reloader.js#L148-L153

Edit: Updated my next.config.js up top.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants