2

I have two projects: Project A and Project B.

Project A

  1. Webpack@2.2.1

  2. Extract-text-webpack-plugin@2.0.0-rc.3

  3. Angular 2.4.3

Project B

  1. Angular 2.4.3

Project B provides a series of modules/components to Project A.

The code is compiled (not bundled) by Project B into a dist folder which then is being used by Project A via npm link.

Right now, with the webpack.common.js settings using the ExtractTextPlugin the browsers throws an Exception: screen shot 2017-02-09 at 12 29 03 pm

This exception is being thrown by Angular 2, but only when this plugin is used. I am saying this, because if I load .css extensions using raw-loader everything works fine, but when using ExtractTextPlugin, it just breaks.

VALID

webpack.config.js

module: {
   rules: [
      {
         test: /\.css$/,
         use: [ "raw-loader" ],
      }
   ]
}

Output:

screen shot 2017-02-09 at 12 43 14 pm

INVALID (using ExtractTextPlugin)

webpack.config.js

module: {
   rules: [
      {
         test: /\.css$/,
         use: ExtractTextPlugin.extract( {
                  fallback: "raw-loader",
                  use: [ "raw-loader" ]
         } )
      }
   }
},
plugins: [
   new ExtractTextPlugin( "[name].css" ),
]

Output:

screen shot 2017-02-09 at 12 30 20 pm

Exception thrown:

Uncaught TypeError: cssText.replace is not a function
    at extractStyleUrls (http://localhost:8080/vendor.js:75001:52)

Node: 6.2.0 OS: macOS Sierra (10.12.2)

Alvaro Contreras
  • 313
  • 3
  • 13
  • See if that helps, worked for me: http://stackoverflow.com/questions/40935793/webpack-sass-build-issue-everything-compiles-fine-then-i-get-a-js-error – mariomol Apr 08 '17 at 03:35

3 Answers3

0

I just ran into this issue because I had a @Component styleUrl that was referencing a valid stylesheet file but the file was empty. Removing the unnecessary styleUrl solved the issue for me.

0

Check answer in this Webpack SASS build issue, everything compiles fine, then I get a JS error

In addition to the answer you can either use require or you can simply import those .css files on top of your component.ts file.

Like import '../assets/app.css';

Abidali
  • 61
  • 1
  • 8
0

Try to add "angular2-template-loader":"^0.6.2" in your dependencies in package.json then exec npm i. This solved my same issue