0

I recently moved Angular project to Webpack build system. After struggling with Angular Dependency Injection issues in JS source code, now that JS errors start occurring in CSS files. And I am totally confused why JS errors are targeting to a CSS file.

The error says;

Uncaught Error: [$injector:unpr] Unknown provider: eProvider <- e

And it occurs on every css file which is tarting with /*!. Also Same error start occurring on different css styles. e.g.

enter image description here

Can someone guide me how such JS injector errors occurring in CSS files?

My webpack config for CSS files are;

  {
    test: /\.css$/,
    loader: ExtractTextPlugin.extract({
      use: [
        { loader: 'css-loader',
          options: {
            modules: false,
            sourceMap: true}
        }}
      ],
      fallback: 'style-loader'
    })
  },

I a requiring all css files together in entry file by;

function requireAll(requireContext) {
  return requireContext.keys().map(requireContext);
}

requireAll(require.context('./../assets/css/', true, /\.css$/));

Can someone guide what's wrong in above config.

Update:

I solved first error on comments of the files by adding minimize: { discardComments: { removeAll: true } into css-loader options. But second issue in styles still persist.

2
  • 1
    The error is definitely not coming from CSS. You are probably seeing it in CSS because something went wrong with the source map creation. Commented Aug 24, 2017 at 0:49
  • But if I remove that css line error do not appear in that css file again. That leads me to believe it’s really in css file. Commented Aug 24, 2017 at 0:51

1 Answer 1

3

Finally found that if you minify AngularJS code with webpack you have incorporate a plugin to solve DI issues.

yarn add -D babel-plugin-angularjs-annotate

And then by adding it into babel plugins;

{
    test: /\.js$/,
    exclude: /(node_modules|bower_components|assets)/,
    use: {
      loader: 'babel-loader?name=js/[hash].[ext]',
      options: {
        presets: ['env'],
        plugins: ['transform-runtime', 'angularjs-annotate']
      }
    }
  }

That solves the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.