addBundles fails in dynamic imports in production build

Hi,

I created a stache helper to import dinamically componentes. It works perfect in development, but it fails in production. The console displays this message:

Error loading “baker@0.0.0#quotation/quotation.stache!can@2.3.27#view/stache/system” from “baker@0.0.0#quotation/quotation” at file:/home/goyo/Documents/Clientes/Prana/Baker/development/baker/src/quotation/quotation.js
addBundles is not a function

The file calling this function is can/view/stache/system.js:

function translate(load) {
	var intermediateAndImports = getIntermediateAndImports(load.source);

	// Add bundle configuration for these dynamic imports
	return addBundles(intermediateAndImports.dynamicImports, load.name).then(function(){

		intermediateAndImports.imports.unshift("can/view/stache/mustache_core");
		intermediateAndImports.imports.unshift("can/view/stache/stache");
		intermediateAndImports.imports.unshift("module");

		return template(intermediateAndImports.imports,
										intermediateAndImports.intermediate);

	});
}

Thats my helper (component hardcoded just for the example):

stache.registerHelper("importComponent", function(options){
  
  var template =
      "<can-import from='baker/quotation/' can-tag='baker-loading'>" +
        "<baker-quotation/>" +
      "</can-import>";
  
  return stache(template)(this, options.helpers, options.nodeList);

});

And in the stache file im calling:

{{{importComponent}}}

In development mode everything works fine, but fails in production. The build process is completed succesfully, without error or warnings messages.

Have no idea why its failing. Any help would be really appreciated, thanks!

I’m not sure, if addBundles is not a function what is it exactly? Try adding console.log(typeof addBundles) and see what you get, maybe.

is can/view/stache/system.js in your bundle ?

maybe you have to require it in your main javscript file like
require("can/view/stache/system"); so that steal knows that it have to bundle it in production.

hopefully my answer make sens :confused:

@matthewp I tried your suggestion and addBundles is returning an object, without any attributes. This function is called in
can/view/stache/system.js (line 7) and stealed like this:

steal("can/view/stache", "can/view/stache/intermediate_and_imports.js", "can/view/stache/add_bundles.js",function(stache, getIntermediateAndImports, addBundles){
...
});

So, addBundles is actually the returned value from can/view/stache/add_bundles.js.
I cant figure out why addBundles is an empty object.

@pYr0x Im not sure about your suggestion, where should i require the file? In the app main js file? Sorry, im newbie with DoneJs.

@justinbmeyer in your bitballs example you are loading components dynamically using a stache helper. I made it the same way and it works great in development, but after building, the component get not resolved, throwing the mentioned error. Cant figure out why. Thanks in advance for any assistance.

can you share a working / failing snippet?
it is hard to say whats going wrong without any debugging.
maybe create a github repo that we can look into