Error when using Extract Text Webpack Plugin

518 views Asked by At

I'm fairly new to Front End and I've been trying to learn webpack. I'm running into some problems when using Extract-Text-Webpack-Plugin that I can't seem to figure out. I'd appreciate any help on this topic. Also, any suggestion / tips are welcomed!

Warning / Error

WARNING in ./~/chokidar/lib/fsevents-handler.js Module not found: Error: Cannot resolve module 'fsevents' in C:\Git\JNJ.Web\src\JNJ.Web.UI\client\node_modules\chokidar\lib @ ./~/chokidar/lib/fsevents-handler.js 7:17-36

ERROR in (webpack)/~/constants-browserify/constants.json Module parse failed: C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\constants-browserify\constants.json Unexpected token (2:12) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:12) at Parser.pp$4.raise (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15) at Parser.pp.unexpected (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10) at Parser.pp.semicolon (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:581:61) at Parser.pp$1.parseExpressionStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:966:10) at Parser.pp$1.parseStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:730:24) at Parser.pp$1.parseBlock (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:981:25) at Parser.pp$1.parseStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:709:33) at Parser.pp$1.parseTopLevel (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25) at Parser.parse (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17) at Object.parse (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39) @ ./~/graceful-fs/polyfills.js 2:16-36

package.json

{
  "name": "OrderEze.CRM",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "",
    "watch": "webpack-dev-server webpack.config.js --progress --colors --watch",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "OrderEze",
  "license": "ISC",
  "dependencies": {
    "babel-core": "6.7.4",
    "babel-loader": "6.2.4",
    "babel-preset-es2015": "6.6.0",
    "babel-preset-react": "6.5.0",
    "babel-preset-stage-1": "6.5.0",
    "classnames": "2.2.0",
    "css-loader": "0.19.0",
    "extract-text-webpack-plugin": "0.8.2",
    "react": "15.4.1",
    "react-dom": "15.4.1",
    "style-loader": "0.12.4",
    "webpack": "1.12.13"
  },
  "devDependencies": {
    "babel-eslint": "7.0.0",
    "eslint": "3.12.2",
    "eslint-config-airbnb": "12.0.0",
    "eslint-plugin-import": "1.16.0",
    "eslint-plugin-jsx-a11y": "2.2.2",
    "eslint-plugin-react": "6.3.0",
    "stylelint": "7.3.1"
  }
}

webpack.config.js

var aliases = require('./task-ticket/aliases.js');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: './task-ticket/index.jsx',
  output: {
    path: path.join(__dirname, '/build'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      test: /\.jsx?$/,
      loader: 'babel-loader',
      query: {
        presets: ['es2015', 'react', 'stage-1']
      }
    },
    {
      test: /\.css?$/,
      loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
    }]
  },
  plugins: [
    new ExtractTextPlugin('style.css')
  ],
  node: {
    fs: 'empty'
  },
  resolve: {
    root: path.resolve(__dirname),
    alias: aliases,
    extensions: ['', '.js', '.jsx', '.css']
  }
};
1

There are 1 answers

1
BrunoLM On

ERROR in (webpack)/~/constants-browserify/ constants.json [...]

Some of the modules you are using need some json files, so you have to allow .json on your resolve.extensions.

resolve: {
  root: path.resolve(__dirname),
  alias: aliases,
  extensions: ['', '.js', '.jsx', '.css', '.json']
}