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

Webpack 2.2.0-rc.4 throws an error because karma-webpack passes incorrect entry option #193

Closed
Reinmar opened this issue Jan 11, 2017 · 38 comments
Assignees

Comments

@Reinmar
Copy link

Reinmar commented Jan 11, 2017

I'm submitting a bug report

Webpack version:

2.2.0-rc.4

Webpack Karma version:

1.8.1

Karma version:

1.3.0

Please tell us about your environment:

OSX 10.12

Current behavior:

11 01 2017 17:47:50.284:ERROR [preprocess]: Can not load "webpack"!
  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   The entry point(s) of the compilation.
   Details:
    * configuration.entry should NOT have less than 1 properties ({
        "keyword": "minProperties",
        "dataPath": ".entry",
        "schemaPath": "#/oneOf/0/minProperties",
        "params": {
          "limit": 1
        },
        "message": "should NOT have less than 1 properties",
        "schema": 1,
        "parentSchema": {
          "minProperties": 1,
          "additionalProperties": {
            "oneOf": [
              {
                "description": "The string is resolved to a module which is loaded upon startup.",
                "minLength": 1,
                "type": "string"
              },
              {
                "description": "All modules are loaded upon startup. The last one is exported.",
                "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues"
              }
            ]
          },
          "description": "Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.",
          "type": "object"
        },
        "data": {}
      }).
      object { <key>: non-empty string | [non-empty string] }
      Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
    * configuration.entry should be a string.
    * configuration.entry should be an array:
      [non-empty string]
    * configuration.entry should be an instance of function
      function returning an entry object or a promise..
    at webpack (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/webpack/lib/webpack.js:20:9)
    at new Plugin (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/karma-webpack/lib/karma-webpack.js:63:18)
    at invoke (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:59:20)
    at get (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:48:43)
    at /www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:71:14
    at Array.map (native)
    at Array.invoke (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:70:31)
    at Injector.get (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules/karma/lib/preprocessor.js:55:20)
    at Array.forEach (native)

Expected/desired behavior:

It worked fine with Webpack 2.2.0-rc.3. Webpack either hasn't been validating the entry option or the validation was more loose.

The config which karma-webpack passes to Webpack is this:

{ plugins: [ CKEditorWebpackPlugin { options: [Object] } ],
  module: { rules: [ [Object], [Object] ] },
  resolveLoader:
   { modules:
      [ 'node_modules',
        '/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules' ] },
  watch: true,
  entry: {},
  output:
   { path: '/_karma_webpack_/',
     publicPath: '/_karma_webpack_/',
     filename: '[name]',
     chunkFilename: '[id].bundle.js' } }

The important part is entry: {}.

@egoroof
Copy link

egoroof commented Jan 11, 2017

I was first 😄

@Reinmar
Copy link
Author

Reinmar commented Jan 11, 2017

You mean #192? Perhaps it's the same issue, but there are no details what went wrong in your ticket.

@Reinmar
Copy link
Author

Reinmar commented Jan 11, 2017

Not sure if this is relevant, but here's the config which we pass to Karma:

{ basePath: '/www/ckeditor5/ckeditor5',
  frameworks: [ 'mocha', 'chai', 'sinon' ],
  files: [ '/www/ckeditor5/ckeditor5/node_modules/ckeditor5-autoformat/tests/**/*.js' ],
  exclude: [ '**/tests/**/_utils/**/*.js', '**/tests/**/manual/**/*.js' ],
  preprocessors: { '/www/ckeditor5/ckeditor5/node_modules/ckeditor5-autoformat/tests/**/*.js': [ 'webpack' ] },
  webpack:
   { plugins:
      [ CKEditorWebpackPlugin {
          options:
           { packages:
              [ '/www/ckeditor5/ckeditor5',
                '/www/ckeditor5/ckeditor5/node_modules' ] } } ],
     module:
      { rules:
         [ { test: /ckeditor5-[^\/]+\/theme\/icons\/[^\/]+\.svg$/,
             use: [ 'raw-loader' ] },
           { test: /\.scss$/,
             use: [ 'style-loader', 'css-loader', 'sass-loader' ] } ] },
     resolveLoader:
      { modules:
         [ 'node_modules',
           '/www/ckeditor5/ckeditor5-dev/packages/ckeditor5-dev-tests/node_modules' ] } },
  webpackMiddleware: { noInfo: true, stats: { chunks: false } },
  reporters: [ 'mocha' ],
  port: 9876,
  colors: true,
  logLevel: 'INFO',
  browsers: [ 'Chrome' ],
  customLaunchers: { CHROME_TRAVIS_CI: { base: 'Chrome', flags: [ '--no-sandbox' ] } },
  singleRun: true,
  concurrency: Infinity,
  browserNoActivityTimeout: 0 }

@TheLarkInn
Copy link

What if you pass entry: []? We did add more constraints on the entry property validation.

@Reinmar
Copy link
Author

Reinmar commented Jan 11, 2017

I added options.entry = []; in webpack.js:

function webpack(options, callback) {
	options.entry = [];
	
	...

And I got the same error.

@Reinmar
Copy link
Author

Reinmar commented Jan 11, 2017

A quick workaround can be to set options.entry to 'whatever' and besides:

ERROR in Entry module not found: Error: Can't resolve 'whatever' in '/www/ckeditor5/ckeditor5'

The tests run and pass :)

@TheLarkInn
Copy link

Could you make a tiny example of this for me to reproduce and add to test cases.

@gyandeeps
Copy link
Contributor

gyandeeps commented Jan 11, 2017

Quick work around is

webpackOptions.entry = function(){return {}};

this way it works like it used to. This style was built for hot reloading stuff.
I dont know if this a good long term solution.

@TheLarkInn TheLarkInn self-assigned this Jan 11, 2017
@TheLarkInn
Copy link

TheLarkInn commented Jan 11, 2017

No this is exactly how we will fix it. Thank you for posting this workaround.

@gyandeeps
Copy link
Contributor

Will send a PR. Thanks @TheLarkInn

@joshwiens
Copy link
Contributor

@gyandeeps - Be mindful to open said pull request to https://github.com/webpack/karma-webpack/tree/v1 & not master. I'll land it as soon as it arrives.

@gyandeeps
Copy link
Contributor

@d3viant0ne It took me a while to figure out why the index.js was empty. lol
here is the PR: #194

@joshwiens
Copy link
Contributor

joshwiens commented Jan 11, 2017

Already merged. @TheLarkInn will cut a patch release shortly

And thank you :)

@gyandeeps
Copy link
Contributor

@d3viant0ne Please merge this PR #195 as I had some lint issues in previous one.

@joshwiens
Copy link
Contributor

Already done. I'm quick with that little green button of doom :)

@TheLarkInn
Copy link

TheLarkInn commented Jan 11, 2017

Before I publish, since I can't test this via our current suite, would someone mind running this commit against their build to ensure it works. I don't have a local reproducible example of this. // @Reinmar @egoroof @gyandeeps

@gyandeeps
Copy link
Contributor

@TheLarkInn I actually tested it with my karma webpack (rc4) setup. That how I figured this out.
I have not tested it with old webpack.

@joshwiens
Copy link
Contributor

@TheLarkInn - Verifying it now

@TheLarkInn
Copy link

Awesome thank you. Also @MikaAK You are the only one with privileges can you publish this?

@TheLarkInn
Copy link

I have the tags pushed and release commits pushed.

@joshwiens
Copy link
Contributor

Besides the usual suspects, i.e. @sokra

@joshwiens joshwiens self-assigned this Jan 11, 2017
@gyandeeps
Copy link
Contributor

@TheLarkInn I saw u created a release but i am not seeing it here anymore: https://github.com/webpack/karma-webpack/releases

Even its not their on npm.

@joshwiens
Copy link
Contributor

I removed the tag as it still throws the same error

@gyandeeps
Copy link
Contributor

huh... it worked for me with webpack (rc4). Can you share your setup or any details.

@joshwiens
Copy link
Contributor

Note to absolutely everyone who will run into this. Most common webpack test configurations set entry: {} to include all of mine.

When updating to "webpack": "2.2.0-rc.4" & "karma-webpack": "1.8.2" you have to pull the entry property if it's set to an empty object so it defaults to a function within karma-webpack and you don't beat your head against the desk and look like a total ass in a github issue like me :)

@gyandeeps
Copy link
Contributor

ah i see. Should we just check if its an empty object (Object.keys(webpackOptions.entry).length === 0) then just replace it with function as well ?

@joshwiens
Copy link
Contributor

I'll stick a note in the tag regarding the required change.

@gyandeeps
Copy link
Contributor

I would recommend 0.9.0 tag release, so that people know that thr are some breaking changes.

@joshwiens
Copy link
Contributor

It's a fix for a breaking change in Webpack ( technically ) not something I would cut a major for.

When using anything but rc.4 it behaves exactly as it did before as it's just failing on schema validation in Webpack.

@gyandeeps
Copy link
Contributor

Sounds good. I will wait for npm to start showing me 1.8.2
Its been lil slow lately.

@gyandeeps
Copy link
Contributor

gyandeeps commented Jan 11, 2017

@TheLarkInn @d3viant0ne Has this been released to npm ?
Its been an hour and it still shows 1.8.1
https://www.npmjs.com/package/karma-webpack

@joshwiens
Copy link
Contributor

No, limited number or people with npm access. Taking care of that now.

joshwiens pushed a commit that referenced this issue Jan 11, 2017
  - defaults webpackOptions.entry to a function

BREAKING CHANGE: Remove entry:{} from test configurations

When updating to `"webpack": "2.2.0-rc.4"` & `"karma-webpack": "1.8.2"` you have to pull the `entry` property if it's set to an empty object so it defaults to a function within karma-webpack
@joshwiens
Copy link
Contributor

joshwiens commented Jan 11, 2017

@gyandeeps - After a bit of discussion, the decision was made to make this a major after all.

Proper tag is cut here - https://github.com/webpack/karma-webpack/releases/tag/v2.0.1

@TheLarkInn should be pushing that up to npm shortly.

@joshwiens
Copy link
Contributor

joshwiens commented Jan 11, 2017

Resolving - https://www.npmjs.com/package/karma-webpack @ 2.0.1

@siemiatj
Copy link

For anyone who stumbles upon that. I've recently migrated to Webpack 2 but my karma config stayed the same. And now when I was trying to run my tests with webpack-karma 2.0.1 I was getting :

13 01 2017 14:45:10.390:ERROR [preprocess]: Can not load "webpack"!
  Error
    at webpack (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/webpack/lib/webpack.js:19:9)
    at new Plugin (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/karma-webpack/lib/karma-webpack.js:67:18)
    at invoke (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:59:20)
    at get (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:48:43)
    at /Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:71:14
    at Array.map (native)
    at Array.invoke (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:70:31)
    at Injector.get (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/karma/lib/preprocessor.js:56:20)
    at Array.forEach (native)
    at createPreprocessor (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/karma/lib/preprocessor.js:75:20)
    at Array.invoke (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:75:15)
    at get (/Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:48:43)
    at /Users/sasklacz/Work/crowdspring/cs3/web/node_modules/di/lib/injector.js:71:14
    at Array.map (native)

which tells nothing at all. After some .console.log('foo') debugging it turned out that it was caused by an error in my karma.webpack config, but the error itself never bubbled up so it was hard to debug :

message: 'Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.\n - configuration.resolve.extensions[0] should not be empty.',

So be sure that your webpack config is correct before anything else :)

@ghost
Copy link

ghost commented Jan 23, 2018

I have the same issue, updated here:
#227 (comment)

@mantupani17
Copy link

i am having the same problem with webpack , i cant understand how do i resolve

@mpavkovic
Copy link

@mantupani17 Have you tried @gyandeeps solution? It worked for me. I've shortened it a bit by using arrow functions

webpackConfig.entry = () => ({});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants