1.3 beta not handling NPM packages with shebangs?

I’m trying out the 1.3 beta and I’ve got everything working apart from one NPM package from Nylas. It contains a dependency called JSONStream which includes the shebang #! /usr/bin/env node on the first line of index.js.

I’m not sure if this is a problem with the package, or a problem with the beta. I didn’t have any problems before with meteorhacks:npm so I’m assuming it’s the latter.

Anyone else run into something similar? This is the error I’m getting.

W20160102-21:43:12.028(-7)? (STDERR) /Users/tim/code/personal/linkmetrics/.meteor/local/build/programs/server/app/app.js:60754
W20160102-21:43:12.028(-7)? (STDERR) #! /usr/bin/env node                                                          
W20160102-21:43:12.028(-7)? (STDERR) ^
W20160102-21:43:12.030(-7)? (STDERR) SyntaxError: Unexpected token ILLEGAL
W20160102-21:43:12.031(-7)? (STDERR)     at /Users/tim/code/personal/linkmetrics/.meteor/local/build/programs/server/boot.js:241:30
W20160102-21:43:12.031(-7)? (STDERR)     at Array.forEach (native)
W20160102-21:43:12.031(-7)? (STDERR)     at Function._.each._.forEach (/Users/tim/.meteor/packages/meteor-tool/.1.1.11-modules.3.1rpyovf++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160102-21:43:12.033(-7)? (STDERR)     at /Users/tim/code/personal/linkmetrics/.meteor/local/build/programs/server/boot.js:137:5

I guess it makes sense why this is happening. The compiled app.js has a section that looks like this:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                     //
// app/node_modules/nylas/node_modules/JSONStream/index.js                                                             //
//                                                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                                       //
#! /usr/bin/env node                                                                                                   // 1
                                                                                                                       // 2
var Parser = require('jsonparse')                                                                                      // 3
  , through = require('through')  

It’s clear that a line beginnning with #! isn’t valid JS. I assume that Node is usually able to handle this because it would be the first line in the file. Not the case with app.js though.

If I test from the node REPL. A shebang is fine, at least with my version of node (I’m not sure how to run this with Meteor’s node).

Tim-rMBP:Desktop tim$ node --version
v0.12.0
Tim-rMBP:Desktop tim$ cat test.js 
#! /usr/local/bin/node
console.log('This works with a shebang');
Tim-rMBP:Desktop tim$ chmod +x test.js
Tim-rMBP:Desktop tim$ ./test.js 
This works with a shebang

Weeeeeeel, I couldn’t work it out so maybe it’s a bug. Reported on Github.

Does anyone have a fix for this? I cant get a Meteor package to work because of a polyfill issue in Meteor 1.3(work in progress since 5 weeks ago), and I cant get the npm package to work because of this issue.

Unfortunately it looks like the issue I reported was moved to the Post 1.3 milestone. Perhaps you could comment on the issue to show that more people than just me are suffering from it.

I ended up moving my code into a package which I believe uses the original NPM integration. This fixed it. The package I’m using is server side only so this was a solution I could live with.