Skip to content

[p5.js 2.0 Bug Report]: Using syntax features from ECMAScript 2022 (and later) results in spurious FES console error #8516

@dontwanttothink

Description

@dontwanttothink

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.2.0

Web browser and version

All browsers (including Safari for macOS 26.2 and Firefox 148.0b13)

Operating system

All operating systems (including macOS 26.2)

Description

The Friendly Errors System has a sketch verification feature that uses Acorn to detect certain programming errors, as described here.

Unfortunately, this feature writes an unfriendly error message to the console whenever JavaScript syntax from ES 2022 or onwards is used in a sketch. To my understanding, the internal p5 code responsible for this can be found in sketch_verifier.js, lines 119–122:

} catch (error) {
  // TODO: Replace this with a friendly error message.
  console.error('Error parsing code:', error);
}

Earlier in the function, Acorn is configured to parse the sketch in ECMAScript 2021 mode:

const ast = parse(code, {
  ecmaVersion: 2021,
  sourceType: 'module',
  locations: true  // This helps us get the line number.
});

(View the full file here.)

I believe this configuration is the cause of the spurious syntax error messages.

Workaround

Users facing this issue can turn off sketch verification, which will disable the console error. However, there is no apparent way to restore the intended functionality —in either case, FES will not identify problematic user-defined variables and functions.

Other FES features, such as parameter validation, will continue to work.

To turn off sketch verification:

p5.disableSketchChecker = true;
// thank you, niell.

For an example of this workaround being used in a sketch, see the links at the end of this issue.

Acknowledgements

Thank you to neill (@nz0h) on Discord for additionally providing links and background.

Steps to reproduce this:

  1. In a sketch, write a class with a static field, as introduced in ECMAScript 2022, using a compatible browser —according to MDN compatibility data, this includes all Chrome releases since January 2019, all Firefox releases since April 2020, and all Safari releases since April 2021.
  2. Observe the error message written to the console.

Snippet:

function setup() {
  createCanvas(400, 400);
}

function draw() {}

class MyClass {
  static myProperty = 3;
}

Sketches (web editor)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions