elidoran / cosmos-browserify

Browserify npm modules for client side in Meteor packages
MIT License
78 stars 12 forks source link

Cannot call method 'split' of undefined #16

Closed sunny-g closed 9 years ago

sunny-g commented 9 years ago

I'm trying to browserify js-stellar-base directly into my app; I currently have it saved to my packages.json and can successfully use the package on the server.

I have a stellar.browserify.js file in client/lib that contains only StellarBase = require('stellar-base') and this is the error I get before it fully exits my Meteor process:

/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:278
                        throw(ex);
                              ^
TypeError: Cannot call method 'split' of undefined
  at Object.exports.parse (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/parse-stack.js:18:26)
  at Object.exception (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:478:28)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/compiler.js:778:20
  at Array.forEach (native)
  at Function._.each._.forEach (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
  at compileUnibuild (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/compiler.js:338:5)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/compiler.js:136:26
  at Array.forEach (native)
  at Function._.each._.forEach (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
  at Object.compiler.compile (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/compiler.js:132:5)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/bundler.js:2090:24
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:264:13
  at [object Object]._.extend.withValue (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:115:14)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:257:29
  at [object Object]._.extend.withValue (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:115:14)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:255:18
  at [object Object]._.extend.withValue (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:115:14)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:246:23
  at [object Object]._.extend.withValue (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:115:14)
  at Object.capture (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:245:19)
  at Object.exports.bundle (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/bundler.js:2040:31)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/run-app.js:554:24
  at time (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/profile.js:231:28)
  at Function.run (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/profile.js:377:12)
  at bundleApp (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/run-app.js:544:34)
  at [object Object]._.extend._runOnce (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/run-app.js:750:35)
  at [object Object]._.extend._fiber (/Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/run-app.js:821:28)
  at /Users/sunnygonnabathula/.meteor/packages/meteor-tool/.1.1.4.1bgon5o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/run-app.js:402:12

Process finished with exit code 8

Any clues as to what's causing this?

elidoran commented 9 years ago

I installed stellar-base into an npm module. Then called browserify (10.2.6) on it manually and it did not succeed. It errors when reading build/Release/native.node file in the ed25519 module used by stellar-base. Says it sees an unexpected character. This makes me think stellar-base doesn't support being browserified.

I looked at their github page and it says to use bower to install it in the browser. It doesn't mention browserify or have a browserify option in its package.json.

When I installed the module on my iMac it compiled some platform specific stuff for ed25519.

Perhaps stellar-base is not browserify-able as-is ?

When using browserify manually it works when i do --exclude "ed25519/**". I used the options file to specify the exclude in a meteor app, but, it still prints the array about being unable to call split on undefined (I edited the plugin to explicitly set the exclude as well and it had no effect). I also excluded the native.node file, as well.

I don't know anything about stellar-base. Is it something which should be browserify-able ?

sunny-g commented 9 years ago

Thanks @elidoran for helping out as I'm terribly unfamiliar with both browserify and webpack.

It looks like stellar-base uses webpack with something (what I believe is a transform-equivalent called a loader) named babel-loader. I found this info from the gruntfile.

I'm in the process of breaking out stellar-base into it's own Meteor package, where I have:

At the moment, this way of going about it is broken, I believe because my options are broken and not exactly parallel to what the original gruntfile is doing. Any thoughts? What did your changes to the browserify.options.json look like (for my own reference)?

elidoran commented 9 years ago

For reference, I started with options:

{
  "exclude" : [ "ed25519/**"]
}

Because, doing browserify ./stellar-base --exclude "ed25519/**" -o stellar.js completed successfully.

However, it didn't help in Meteor. I then changed Browserify to read that option and explicitly call browserify.exclude pattern in the plugin. That still didn't solve it.

I looked at the gruntfile you referenced. It uses webpack and ignores all .node files, which makes sense because that's what I was trying to ignore with the ed25519 stuff. It also doesn't build from the "main" script; it builds from src/browser.js instead. Perhaps if they set a "browserify" property in their package.json file which pointed at that file it would help.

I have a better solution for you tho. Their README says they publish to Bower. There is a meteor package for bower: mquandalle:bower. So, I tried it and it works with stellar-base.

I have a simple meteor app I test things on. I added that bower package to it, added the below "bower.json" file in app/client/, the app ran, and StellarBase was available in the JavaScript console.

{
  "name": "testcb",
  "version": "0.1.0",
  "dependencies": {
    "stellar-base": "0.3.10"
  },
  "private": true
}

Please, let me know if that works for you.