localvoid / ivi

Lighweight Embeddable Web UI Library
MIT License
723 stars 22 forks source link

Trouble bundling ivi with webpack #2

Closed marvinhagemeister closed 7 years ago

marvinhagemeister commented 7 years ago

I'm having trouble bundling ivi with wepback and the stack trace isn't that meaningful. This even happens with a simple app like this:

import { render } from "ivi";
import * as h from "ivi-html";

render(h.div().children("Hello World"), document.getElementById("root"));

Stacktrace:

bundle.js:5015 Uncaught Error: Cannot find module "."
    at webpackMissingModule (bundle.js:5015)
    at Object.SVG_NAMESPACE (bundle.js:5015)
    at __webpack_require__ (bundle.js:20)
    at Object.webpackEmptyContext.keys (bundle.js:12009)
    at __webpack_require__ (bundle.js:20)
    at Object.<anonymous> (bundle.js:6461)
    at __webpack_require__ (bundle.js:20)
    at module.exports.ctor.super_ (bundle.js:63)
    at bundle.js:66

I'm a bit confused as to what is actually happening here. Webpack seems to stumble on the render import. A repo to easily reproduce the bug is here: https://github.com/marvinhagemeister/ivi-webpack-problem

localvoid commented 7 years ago

webpack-dev-server has a bug https://github.com/webpack/webpack-dev-server/issues/984

marvinhagemeister commented 7 years ago

Oh wow, I found the issue. It was a simple misconfiguration on my part. To inject globals I used the ProvidePlugin and not DefinePlugin. The former is used to replace modules and the latter simply defines a global variable.

Sorry for the confusion!

plugins: [
    new webpack.DefinePlugin({ // was using `ProvidePlugin` instead :/
      __IVI_DEV__: true,
      __IVI_BROWSER__: true,
    }),
  ],
localvoid commented 7 years ago

Ah, sorry, forgot that I've changed to DefinePlugin when I've tried to find a problem. Just tried different things and the last problem was with missing loglevel package, I though that it was the main problem.