Skip to content

Conversation

@Anirudh-x
Copy link

Fixes #8370 - p5 does not work with TypeScript / module importing

Added 'export default p5' alongside the existing CommonJS export to support modern ES6 imports like 'import p5 from "p5"'

Resolves #8370

Changes:
Added ES6 default export (export default p5) alongside the existing CommonJS export (module.exports = p5) in app.js to support modern ES6/TypeScript module imports.

Screenshots of the change:
N/A - This is a module export change with no visual impact.

PR Checklist

Fixes processing#8370 - p5 does not work with TypeScript / module importing

Added 'export default p5' alongside the existing CommonJS export
to support modern ES6 imports like 'import p5 from "p5"'
Copilot AI review requested due to automatic review settings January 23, 2026 14:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses issue #8370 by adding ES6 default export support to enable TypeScript and modern ES module imports of p5.js. The change adds export default p5 alongside the existing module.exports = p5 in the main entry point file.

Changes:

  • Added ES6 default export (export default p5) to src/app.js to support modern module imports like import p5 from 'p5'

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 106 to +107
module.exports = p5;
export default p5;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both module.exports = p5; and export default p5; in the same file can cause conflicts during the build process. When Babel transpiles ES6 to CommonJS, export default becomes exports.default = p5, which creates a different export structure than module.exports = p5.

The order and interaction between these two statements depends on the Babel configuration and build system. Consider one of these approaches:

  1. Remove module.exports = p5 and rely solely on export default p5, letting Babel handle the CommonJS transformation
  2. Keep only module.exports = p5 and ensure the build system's UMD wrapper properly exposes it for ES6 imports
  3. Verify through build and integration testing that both exports work correctly together in the current Browserify+Babel setup

The PR should include tests or build verification demonstrating that both CommonJS (require('p5')) and ES6 (import p5 from 'p5') imports work correctly with the compiled output.

Suggested change
module.exports = p5;
export default p5;
export default p5;

Copilot uses AI. Check for mistakes.
import './core/init';

module.exports = p5;
export default p5;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR checklist indicates that unit tests are not included or updated. Given that this change modifies the module export mechanism (which is critical for library consumers), tests should be added to verify:

  1. The built library can be imported using ES6 syntax (import p5 from 'p5')
  2. The built library can still be imported using CommonJS syntax (const p5 = require('p5'))
  3. Both import methods provide the same p5 object with all expected properties and methods

Consider adding integration tests that actually import the built library (from lib/p5.js) using both module systems to ensure backwards compatibility and that the new ES6 import works as intended.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

p5 does not work with Typescript / module importing

1 participant