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

Add browserify support. #128

Open
feross opened this Issue Apr 4, 2016 · 7 comments

Comments

4 participants
@feross

feross commented Apr 4, 2016

The following code fails using the npm package with Browserify:

var benchmark = require('benchmark')
var suite = benchmark.Suite()

With the following error:

Uncaught TypeError: benchmark.Suite is not a constructor

You can quickly see it happening if you use RequireBin and paste the above code.

@jdalton jdalton added the invalid label Apr 4, 2016

@jdalton

This comment has been minimized.

Member

jdalton commented Apr 4, 2016

Hi @feross!

I believe that means lodash isn't being loaded properly.

@jdalton jdalton closed this Apr 4, 2016

@feross

This comment has been minimized.

feross commented Apr 4, 2016

@jdalton This was a fresh npm install, and I can confirm that lodash is in the node_modules folder.

@jdalton jdalton added enhancement and removed invalid labels Apr 4, 2016

@jdalton jdalton reopened this Apr 4, 2016

@jdalton jdalton changed the title from Uncaught TypeError: benchmark.Suite is not a constructor to Add browserify support. Apr 4, 2016

@jdalton

This comment has been minimized.

Member

jdalton commented Apr 4, 2016

Ah ok. Let me know if 7de5705 or c588a6b helps.

@feross

This comment has been minimized.

feross commented Apr 4, 2016

Yep, works better.

Getting errors on this line

(program):1 Uncaught ReferenceError: Benchmark is not defined

But it doesn't seem to be preventing things from working. It's just spewing in the console at the moment.

@jdalton

This comment has been minimized.

Member

jdalton commented Apr 4, 2016

I'll keep digging.

@julianvmodesto

This comment has been minimized.

julianvmodesto commented Jan 10, 2017

Using Webpack + Babel for my client-side. This thread was helpful and this is what I ended up with that works for me:

// package.json
  "dependencies": {
    "benchmark": "^2.1.3",
    "lodash": "^4.17.4",
  }

// webpack.config.js
  ...
  module: {
    noParse: [
      /benchmark/,
    ]
  },
  ...
import _ from 'lodash';
import process from 'process';

const benchmark = require('benchmark');
const Benchmark = benchmark.runInContext({ _, process });
window.Benchmark = Benchmark;

Seems like the noParse was important.

@drewlustro

This comment has been minimized.

drewlustro commented Sep 6, 2017

Thanks @julianvmodesto !

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