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

Not working with Webpack 2 beta #22

Open
sudsy opened this issue Aug 17, 2016 · 4 comments
Open

Not working with Webpack 2 beta #22

sudsy opened this issue Aug 17, 2016 · 4 comments

Comments

@sudsy
Copy link

sudsy commented Aug 17, 2016

My tests that were working with Webpack 1 and rewire now fail under webpack 2 beta.

I receive the error:

C:\Users\sudsy\Development\gen3\PVL.Content\tests\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:86
        if(callback.stack) {
                   ^

TypeError: Cannot read property 'stack' of undefined
    at Tapable.doResolve (C:\Users\sudsy\Development\gen3\PVL.Content\tests\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:86:13)
    at Tapable.next (C:\Users\sudsy\Development\gen3\PVL.Content\tests\node_modules\enhanced-resolve\lib\ModuleAliasPlugin.js:37:19)
    at Tapable.<anonymous> (C:\Users\sudsy\Development\gen3\PVL.Content\tests\node_modules\enhanced-resolve\lib\ModuleAliasPlugin.js:42:5)
@gkovacs
Copy link

gkovacs commented Jan 22, 2017

With webpack 2.2.0, the error is now:

geza@gezamac ~/D/habitlab> karma start
webpack: Using compiler.parser is deprecated.
Use compiler.plugin("compilation", function(compilation, data) {
  data.normalModuleFactory.plugin("parser", function(parser, options) { parser.plugin(/* ... */); });
}); instead. It was called at RewirePlugin.apply (/Users/geza/Dropbox/habitlab/node_modules/rewire-webpack/lib/RewirePlugin.js:22:21).
22 01 2017 01:01:42.072:ERROR [preprocess]: Can not load "webpack"!
  TypeError: Cannot read property 'apply' of null
    at RewirePlugin.apply (/Users/geza/Dropbox/habitlab/node_modules/rewire-webpack/lib/RewirePlugin.js:48:30)
    at Compiler.apply (/Users/geza/Dropbox/habitlab/node_modules/tapable/lib/Tapable.js:306:16)
    at webpack (/Users/geza/Dropbox/habitlab/node_modules/webpack/lib/webpack.js:32:19)
    at new Plugin (/Users/geza/Dropbox/habitlab/node_modules/karma-webpack/lib/karma-webpack.js:65:18)
    at invoke (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:59:20)
    at get (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:48:43)
    at /Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:71:14
    at Array.map (native)
    at Array.invoke (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:70:31)
    at Injector.get (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/Users/geza/Dropbox/habitlab/node_modules/karma/lib/preprocessor.js:55:20)
    at Array.forEach (native)
    at createPreprocessor (/Users/geza/Dropbox/habitlab/node_modules/karma/lib/preprocessor.js:74:20)
    at Array.invoke (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:75:15)
    at get (/Users/geza/Dropbox/habitlab/node_modules/di/lib/injector.js:48:43)
22 01 2017 01:01:42.148:WARN [karma]: No captured browser, open http://localhost:9876/
22 01 2017 01:01:42.160:INFO [karma]: Karma v1.4.0 server started at http://0.0.0.0:9876/
22 01 2017 01:01:42.161:INFO [launcher]: Launching browser Chrome_without_security with unlimited concurrency
22 01 2017 01:01:42.163:ERROR [karma]: Found 1 load error

@gkovacs
Copy link

gkovacs commented Jan 22, 2017

I took a stab at fixing this issue of webpack 2 compatibility. If you apply my changes at gkovacs@31da0a9 it resolves both the issues above, however the .__get__ property is not available on the module, so apparently rewire.loader.js is not being correctly loaded. If someone can figure out how to fix that last issue then rewire-webpack will be fully compatible with webpack 2.

@gkovacs
Copy link

gkovacs commented Jan 23, 2017

A hackish workaround for now until rewire-webpack is fixed to work with webpack 2 is to just insert the __get__ and __set__ manually into the module you're testing. ie (livescript/coffeescript)

export __get__ = (name) ->
  return eval(name)

export __set__ = (name, val) ->
  eval(name + ' = val')

I believe in javascript it would be

module.exports.__get__ = function(name) {
  return eval(name);
}

module.exports.__set__ = function(name, val) {
  eval(name + ' = val');
}

And clear the module cache before each require, via

delete require.cache[require.resolve('libs_frontend/dom_utils')]

To see a full example see https://github.com/habitlab/habitlab/blob/539443c123d335099cafdde2df35b40264a0acad/test/libs_frontend/dom_utils.test.ls and https://github.com/habitlab/habitlab/blob/539443c123d335099cafdde2df35b40264a0acad/src/libs_frontend/dom_utils.ls

@rensbaardman
Copy link

For webpack 4 support, you can use my fork rensbaardman/rewire-webpack-plugin.

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

Successfully merging a pull request may close this issue.

3 participants