Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the correct way to import behaviortree in a webpack app? (You may need an appropriate loader to handle this file type)

EnricoPietrocola opened this issue · comments

As of today I have been using behaviortree in node and it's been working great.

I am now in the process of adding behaviortree in my gui app, built with webpack, and I can't seem to get it working.
I either get a

You may need an appropriate loader to handle this file type

or

Selector is not a constructor

I tried many things, from all possible import/require, paths to the node_module combinations, with no luck.
I realize this might just be me being still ignorant about webpack but I can't find a way to make it work.
What would be the best way to create behaviortree objects in a webpack packed app?

This is the basic code I am using:

import {GBranchNode} from "./BranchNode";  //my implementation of the GUI Branchnode class, not BT
import * as main from "../src";
import Sequence from "behaviortree/src";    //behaviortree Sequence class

export class GRoot extends GBranchNode{
    constructor(context, x = 10, y = 10)
    {
        super("Root", context, false, x, y)
        this.priority = 0;
        this.setPriority(this.priority)
    }

    action(){
        super.action()
        main.result = new Sequence({nodes: []})         //Constructor is not defined (or, "get a loader message")
    }
}

After more testing, trying babel and more, it looks like setting webpack "mode" property to "production" instead of "development" has fixed the issue, which still is kind of annoying because build time takes 5 seconds instead of 800ms, but at least now it works great (I am now testing on 2.1.0)

Yes this was totally fixed, it was caused by a combination of bad setups between Webpack and Electron. I activated node in Electron and everything worked out

Ah, glad you figured it out, and wrote your solution down. Maybe it is help to the next one trying something similar :-)