Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Uncaught TypeError when using this plugin #16

Open
typeofweb opened this issue Aug 2, 2017 · 5 comments
Open

Uncaught TypeError when using this plugin #16

typeofweb opened this issue Aug 2, 2017 · 5 comments

Comments

@typeofweb
Copy link

typeofweb commented Aug 2, 2017

I'm working on a starter for React + ReasonML + webpack. I wanted to use webpack-common-shake plugin. Unfortunately, when enabled, I get this TypeError:

Uncaught TypeError: this.number is not a function

How to reproduce?

Expected result:

You can see Hello world, Anne! in the browser. No errors in the console

Current result:

Uncaught TypeError: this.number is not a function
    at Object.numberString (main.js:4385)
    at new SockJS (main.js:64)
    at socket (socket.js:7)
    at Object.<anonymous> (main.js:10282)
    at Object.<anonymous> (main.js:10307)
    at __webpack_require__ (bootstrap b5203ed…:669)
    at fn (bootstrap b5203ed…:87)
    at Object.<anonymous> (main.js:17077)
    at __webpack_require__ (bootstrap b5203ed…:669)
    at validateFormat (bootstrap b5203ed…:715)

Workaround:

Disable webpack-common-shake plugin in webpack.config.js

@netil
Copy link

netil commented Aug 3, 2017

I have same issue, and figured out that webpack-common-shake is doing some transformation on reserved words.
The part of SockJS contains following code:

, number: function(max) {
    return Math.floor(Math.random() * max);
  }

, numberString: function(max) {
    var t = ('' + (max - 1)).length;
    var p = new Array(t + 1).join('0');
    return (p + this.number(max)).slice(-t);
  }

After the common-shake plugin above code is transformed as:

, "number": ((function(max) {
    return Math.floor(Math.random() * max);
  }),null)

which this.number ended up being null, instead of function.

@typeofweb
Copy link
Author

👍 That's exactly the same problem I have. It seems that the comma operator shouldn't be here.

@indutny
Copy link
Owner

indutny commented Aug 8, 2017

Hello!

I'll take a look at it later this week. It has nothing to do with reserved words, however, as number is not one of them.

The way it adds comma and null is a normal mode of operation. This function is unused in this library, so it isolates it for later removal by UglifyJS.

Will see what's the underlying problem a bit later.

Thanks for reporting!

@usirin
Copy link

usirin commented Oct 18, 2017

Hello @indutny thanks for all the work you have done so far! It definitely helped me a lot!

But starting from today, i started to encounter this issue as well. Do you have any updates regarding this problem?

@CertainLach
Copy link
Contributor

CertainLach commented Dec 31, 2018

Having same issue when trying to use createVerify reexported from browserify-sign by browserify-crypto
image

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

No branches or pull requests

5 participants