In a trivial webpack 2 project, I'm trying to use this UMD module: https://github.com/Offirmo/simple-querystring-parser/blob/master/index.js
There is no transpilation error.
However, this ends up with this error in the browser:
Uncaught TypeError: Cannot set property 'SimpleQuerystringParser' of undefined
It seems webpack wrapping is providing an environment that the UMD snippet can't recognize.
- I coulndn't find any hint in webpack doc
- Searching google for "consuming UMD with webpack" didn't come up with interesting results
- StackOverflow wasn't helpful either.
So how can I consume my UMD library in webpack?
Note: yes, the target UMD library is mine, but it uses a legit UMD snippet from the official UMD website. Any suggestions are welcome.
In the end, I debbuged the UMD wrapper under webpack 2 environment and was able to come up with an improved UMD wrapper which also works in webpack 2: (available in a gist here https://gist.github.com/Offirmo/ec5c7ec9c44377c202f9f8abcacf1061#file-umd-js)
For information, the original wrapper, not working in webpack 2: (from here https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js)
Fortunately I was the owner of the lib and could fix it.