azerion / phaser-input

Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.
MIT License
204 stars 65 forks source link

Phaser 2 Webpack build error #72

Open dougSmall31 opened 6 years ago

dougSmall31 commented 6 years ago

Hello,

I'm getting this error only on the production build, when I'm running on my local dev environment everything works fine.

Uncaught TypeError: Cannot set property 'game' of undefined
    at n.PluginManager.add (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at n.GameObjectFactory.plugin (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at e.value (bundle.js?b6ee61c795d18e338b66:1)
    at n.StateManager.preUpdate (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at e.updateLogic (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at e.update (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at n.RequestAnimationFrame.updateRAF (vendor.bundle.js?b6ee61c795d18e338b66:1)
    at window.requestAnimationFrame.forceSetTimeOut._onLoop (vendor.bundle.js?b6ee61c795d18e338b66:1)

When I completely remove the phaser-input field from that state the game runs fine in the production build. That leads me to believe it's an issue with phaser-input and webpack. I followed the instructions on issue #7 but am still having issues.

module: {
    rules: [
      {
        test: /\.js$/,
        use: ["babel-loader"],
        include: path.join(__dirname, "src")
      },
      { test: /pixi\.js/, use: ["expose-loader?PIXI"] },
      { test: /phaser-split\.js$/, use: ["expose-loader?Phaser"] },
      { test: /p2\.js/, use: ["expose-loader?p2"] },
      //added for phaser-input
      {
        test: /phaser\-input\.js$/,
        use: "exports-loader?PhaserInput=PhaserInput"
      },
      { test: /\.ts$/, enforce: "pre", loader: "tslint-loader" },
      { test: /\.ts$/, loader: "ts-loader" }
    ]
  },
  node: {
    fs: "empty",
    net: "empty",
    tls: "empty"
  },
  resolve: {
    extensions: [".ts", ".js"],
    alias: {
      phaser: phaser,
      pixi: pixi,
      p2: p2,
      "phaser-input": path.join(
        __dirname,
        "/node_modules/@orange-games/phaser-input/build/phaser-input.js"
      )
    }
  }

Any help is much appreciated.

dougSmall31 commented 6 years ago

@AleBles

AleBles commented 6 years ago

The things I can think of is that you import the wrong thing (should be import 'phaser-input';) or that the exports loader is the wrong thing for the job.

You're best off with someone rather proficient in webpack, and I'm not that guy. Sorry