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

Add browserify support. #128

Open
feross opened this issue Apr 4, 2016 · 8 comments
Open

Add browserify support. #128

feross opened this issue Apr 4, 2016 · 8 comments
Labels

Comments

@feross
Copy link

@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
Copy link
Member

@jdalton 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
Copy link
Author

@feross 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 reopened this Apr 4, 2016
@jdalton jdalton changed the title Uncaught TypeError: benchmark.Suite is not a constructor Add browserify support. Apr 4, 2016
@jdalton
Copy link
Member

@jdalton jdalton commented Apr 4, 2016

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

@feross
Copy link
Author

@feross 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
Copy link
Member

@jdalton jdalton commented Apr 4, 2016

I'll keep digging.

@julianvmodesto
Copy link

@julianvmodesto 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
Copy link

@drewlustro drewlustro commented Sep 6, 2017

Thanks @julianvmodesto !

@heapwolf
Copy link

@heapwolf heapwolf commented Feb 27, 2019

Result from piping browserify output to chrome headless.

> browserify --bare ./test/perf.js | tape-run

TypeError: Cannot read property 'parentNode' of undefined
    at runScript (http://localhost:52210/bundle.js:902:27)
    at createFunction (http://localhost:52210/bundle.js:755:9)
    at createFunction (http://localhost:52210/bundle.js:762:44)
    at createCompiled (http://localhost:52210/bundle.js:1952:23)
    at clock (http://localhost:52210/bundle.js:1846:58)
    at clock (http://localhost:52210/bundle.js:2056:20)
    at cycle (http://localhost:52210/bundle.js:2245:49)
    at Benchmark.run (http://localhost:52210/bundle.js:2352:13)
    at execute (http://localhost:52210/bundle.js:1098:74)
    at invoke (http://localhost:52210/bundle.js:1208:20)

This issue is caused by the assumption that there will be a script tag in the page (in some cases this is not true)...

sibling = doc.getElementsByTagName('script')[0],

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

Successfully merging a pull request may close this issue.

None yet
5 participants