Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locals.shift() #3

Open
bmcmahen opened this issue Apr 7, 2014 · 10 comments
Open

locals.shift() #3

bmcmahen opened this issue Apr 7, 2014 · 10 comments

Comments

@bmcmahen
Copy link

bmcmahen commented Apr 7, 2014

I keep running into this error when attempting to use the bundler:

Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-bundler/lib/pages.js:35
  var boot = locals.shift();
                    ^
TypeError: Object #<Object> has no method 'shift'
    at Object.module.exports [as pages] (/Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-bundler/lib/pages.js:35:21)
    at Resolver.<anonymous> (/Users/bmcmahen/Development/KnowEugenics/app/bin/build2.js:150:26)
    at processImmediate [as _immediateCallback] (timers.js:385:17)

I'm using the latest component-builder on npm. Is this a compatibility issue?

@jonathanong
Copy link
Contributor

oh i think i just need to update. let me push an update

@bmcmahen
Copy link
Author

bmcmahen commented Apr 7, 2014

Still getting the same error. It looks like the bundler is expecting locals to be an array, but it's actually an object? I'm running bundler 0.0.1 and builder 1.1.2.

@bmcmahen
Copy link
Author

bmcmahen commented Apr 7, 2014

Oh jeez, looking at the example again I think I may just be using it wrong. Let me try to figure this out...

@jonathanong
Copy link
Contributor

yeah... i need to update this stuff after 1.0.0 lands

@jonathanong
Copy link
Contributor

hmmm maybe i shouldn't use .shift() there as it's destructive. what are you currently doing? maybe i can help figure out what's going wrong.

@jonathanong
Copy link
Contributor

oh. if you're passing in the component.json, be sure to update to .locals instead of .local

@bmcmahen
Copy link
Author

bmcmahen commented Apr 8, 2014

Alright, here is my building code:

function bundleComponets(){
  var options = {
    install: true,
    out: __dirname + '/../client/components'
  };

  var root = require('../component.json');
  var bundle = bundler.pages(root);

  resolve(process.cwd(), options, function(err, tree){
    if (err) throw err;
    var bundles = bundle(tree);
    Object.keys(bundles).forEach(function(name){
      buildScripts(bundles[name], getBuildPath(name));
    });
  });
}

function buildScripts(tree, buildPath){
  build.scripts(tree)
    .use('scripts', build.plugins.js())
    .use('json', build.plugins.json())
    .use('templates', build.plugins.string())
    .use('templates', jade({
      runtime: true
    }))
    .end(function(err, string){
      if (err) throw err;
      if (!string) return;
      string = jade.runtime + build.scripts.require + string;
      string += 'require("' + canonical(tree).canonical + '")\n';
      if (program.production) string = minify.js(string);
      write(buildPath + '.js', string);
    });
}

and I'm now getting the following error:

/Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/build/builders/scripts.js:447
  var scripts = tree.node.scripts;
                         ^
TypeError: Cannot read property 'scripts' of undefined
    at Scripts.canonical (/Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/build/builders/scripts.js:447:26)
    at /Users/bmcmahen/Development/KnowEugenics/app/bin/build2.js:70:31
    at /Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/build/builders/builder.js:578:9
    at next (/Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/node_modules/chanel/lib/proto.js:246:5)
    at Channel.onevent (/Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/node_modules/chanel/lib/proto.js:182:9)
    at Channel.g (events.js:190:16)
    at Channel.EventEmitter.emit (events.js:98:17)
    at /Users/bmcmahen/Development/KnowEugenics/app/node_modules/component-builder/node_modules/chanel/lib/proto.js:130:10
    at processImmediate [as _immediateCallback] (timers.js:385:17)

And my component.json file is quite simple:

{
  "name": "app",
  "paths": ["client"],
  "locals": [
    "boot",
    "mindmap"
  ]
}

Any ideas?

@jonathanong
Copy link
Contributor

oh you know what. the bundler returns {<bundle>: [<stuff>]}. when you're passing scripts.canonical(tree), you're passing the array, not the tree.

maybe i should just have the bundlers return trees since the builders automatically flatten now.

another option is to hardcode string += 'require("./client/boot")\n'; (that's what i'm doing now since it's easier)

@jonathanong
Copy link
Contributor

nope. can't return trees. i'll have canonical support flattened trees

@bmcmahen
Copy link
Author

bmcmahen commented Apr 8, 2014

cool. for now I'll just use the require("./client/boot")\n';. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants