devote / HTML5-History-API

HTML5 History API expansion for browsers not supporting pushState, replaceState
http://spb-piksel.ru
MIT License
1.02k stars 182 forks source link

Can not bundle package using webpack 2 #104

Closed dpashin closed 7 years ago

dpashin commented 7 years ago

Can not bundle package using webpack 2

Hi. Now i'm using html5-history-api and webpack 1.14.0, and all works fine. I've tried to upgrade webpack to 2.x and got error "Uncaught ReferenceError: Invalid left-hand side in assignment"

Seems that webpack rewrites this code and something goes wrong.

(function(factory) {
  if (typeof define === 'function' && define['amd']) {
    if (typeof requirejs !== 'undefined') {
      // https://github.com/devote/HTML5-History-API/issues/73
      var rndKey = '[history' + (new Date()).getTime() + ']';
      var onError = requirejs['onError'];
      factory.toString = function() {
        return rndKey;
      };
      requirejs['onError'] = function(err) {         // <==== ERROR HERE
        if (err.message.indexOf(rndKey) === -1) {
          onError.call(requirejs, err);
        }
      };
    }
    define([], factory);
  }

Steps to reproduce:

  1. git clone git@github.com:dpashin/history-bug.git
  2. npm i
  3. node node_modules/webpack/bin/webpack.js
  4. open index.html in browser and you will see error in console
artur-code commented 7 years ago

I am also getting this error after switching to webpack 2

artur-code commented 7 years ago

@dpashin You managed to solve the problem ?

dpashin commented 7 years ago

@superartgun, as a workaround, i can fork repo and remove this block
if (typeof requirejs !== 'undefined') {...}

than all builds fine. Of course, it's a bad solution. I'm waitng for an answer.

spac-valentin commented 7 years ago

Same issue here, waiting for a fix.

devote commented 7 years ago

Hello!

I have no way to check it out right now.

Tell me, what type of a variable requirejs at the time of the error?

devote commented 7 years ago

The necessary changes have been made. I apologize for the delay.

dpashin commented 7 years ago

@devote, did you published new version to npm registry? I don't see new version here https://www.npmjs.com/package/html5-history-api

devote commented 7 years ago

Sorry! Published!

dpashin commented 7 years ago

Thanks! all works.