Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Add browserify support. #128

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

Add browserify support. #128

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

Comments

@feross
Copy link

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 commented Apr 4, 2016

Hi @feross!

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

@jdalton jdalton closed this as completed Apr 4, 2016
@feross
Copy link
Author

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 commented Apr 4, 2016

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

@feross
Copy link
Author

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 commented Apr 4, 2016

I'll keep digging.

@julianvmodesto
Copy link

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

Thanks @julianvmodesto !

@heapwolf
Copy link

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:https://localhost:52210/bundle.js:902:27)
    at createFunction (http:https://localhost:52210/bundle.js:755:9)
    at createFunction (http:https://localhost:52210/bundle.js:762:44)
    at createCompiled (http:https://localhost:52210/bundle.js:1952:23)
    at clock (http:https://localhost:52210/bundle.js:1846:58)
    at clock (http:https://localhost:52210/bundle.js:2056:20)
    at cycle (http:https://localhost:52210/bundle.js:2245:49)
    at Benchmark.run (http:https://localhost:52210/bundle.js:2352:13)
    at execute (http:https://localhost:52210/bundle.js:1098:74)
    at invoke (http:https://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],

@jonkoops
Copy link

I am getting the same kind of issue when using Rollup, more info in #244

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

6 participants