P5.js: Failure to construct p5 in instance mode when using custom bundles (combineModules)

Created on 12 Jul 2019  路  5Comments  路  Source: processing/p5.js

When creating a custom bundle using combineModules, p5 fails to instantiate with the error:
p5 is not a constructor

Nature of issue?

  • [x] Found a bug

Most appropriate sub-area of p5.js?

  • [x] Build system

Which platform were you using when you encountered this?

  • [x] Desktop/Laptop

Details about the bug:

  • p5.js version: https://github.com/processing/p5.js/commit/99252b96aff3d80d5f92f879d8d81a74e0453033
  • Web browser and version: Chrome 75.0.3770.100
  • Steps to reproduce this:
    npm run grunt combineModules:core/shape:color:math:image
    Use the following for sketch.js in emptyExample

    const s = ( sketch ) => {
    
     let x = 100;
     let y = 100;
    
     sketch.setup = () => {
       sketch.createCanvas(200, 200);
     };
    
     sketch.draw = () => {
       sketch.background(0);
       sketch.fill(255);
       sketch.rect(x,y,50,50);
     };
    };
    
    let myp5 = new p5(s);
    

    Results in error p5 is not a constructor

build bug

Most helpful comment

@sakshamsaxena thanks for following up on this.

All 5 comments

@outofambit any idea why this happens? I assume there are steps in the regular build process that are not included in combineModules. Is this a correct assumption?

@hsab It may be the browserify step not exposing a p5 global on the combine module step

@hsab @limzykenneth yep that's my theory too. i think there also might be an error that happens if the final export of p5 from the bundle doesn't use the old school way of exporting. (i think it confuses browserify somehow?)

i believe that's why app.js uses this:

https://github.com/processing/p5.js/blob/5df69d9ebdd58eedff35deb472c0d0b13d1a7051/src/app.js#L87

ah yes, that's what @hsab figured out in https://github.com/processing/p5.js/issues/3758#issuecomment-496858975!

@sakshamsaxena thanks for following up on this.

4211 is up now, should fix this for once and all

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ogoossens picture ogoossens  路  3Comments

stalgiag picture stalgiag  路  3Comments

swirly picture swirly  路  3Comments

kappaxbeta picture kappaxbeta  路  3Comments

stalgiag picture stalgiag  路  3Comments