clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

Clearbit Incompatible with Webpack/Browserify #36

Closed andymjames closed 6 years ago

andymjames commented 6 years ago

The Needle package you forked is where the issue lies. The way it gets the version out of package.json is incompatible with tools like Webpack and Browserify, which work better using a require() style syntax.

In good news, the owner of the original repo found and fixed this over 2 years ago. https://github.com/tomas/needle/commit/f7a72f18ad554b2416471134834aaed950f32ee4

In more good news, it's a very straight forward 1 line fix.

davidlumley commented 6 years ago

Thanks for letting us know! I'll try and have a look at this over the next couple of days.

andymjames commented 6 years ago

Great! It just occurred to me that you probably want to reproduce it yourself...

I use webpack to give me one giant JS file I can upload to AWS to use as a Lambda function. You can probably repro the issue though by locally running a webpack output file as a Node app.

My webpack.config.js looks like this:

const path = require('path');
module.exports = {
  entry: "./main-node-file.js",
  output: {
      path: path.join(__dirname, 'webpack-out'),
      filename: "main-node-file.js",
      libraryTarget: 'commonjs'
  },
  target: 'node'
};

That causes the output of using webpack to be a file of the same name as the main file, but in a sub dir called webpack-out and the output file has all the dependencies also contained within the one file.

Since that one file is the only thing I send to AWS when that one Needle line tries to read a file at ../package.json it doesn't exist. However webpack is smart enough that it would have included the contents of package.json in the mega-file output, had it been referenced via a require() statement.

I hope that helps explain more and gives you a path towards repo'ing!

andymjames commented 6 years ago

@davidlumley I was kind of hoping you'd have some initial feedback by now. Is there any more information I can provide?

I don't want to sound impatient, but this issue is blocking me from deploying a new service to production that will ultimately increase my company's Clearbit usage.

davidlumley commented 6 years ago

Hey @andymjames sorry for the delay, have been dealing with some more pressing matters.

Definitely don't want to block you though, so are you able to either: a) Fork this repo, add your change, and use that forkin your app b) Submit a PR with some clear tests that will enable me to quickly test and deploy

I've blocked time off to look at this, but want to make sure you've got a path forward in the meantime.

andymjames commented 6 years ago

@davidlumley Do you know when this update will be published to NPM?

cancan101 commented 5 years ago

Has this fix been released? I am seeing issues trying to require clearbit using runkit: https://npm.runkit.com/clearbit