-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add ES6 default export for TypeScript/ES module support #8434
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
base: main
Are you sure you want to change the base?
Conversation
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"'
There was a problem hiding this 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 likeimport p5 from 'p5'
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| module.exports = p5; | ||
| export default p5; |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
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:
- Remove
module.exports = p5and rely solely onexport default p5, letting Babel handle the CommonJS transformation - Keep only
module.exports = p5and ensure the build system's UMD wrapper properly exposes it for ES6 imports - 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.
| module.exports = p5; | |
| export default p5; | |
| export default p5; |
| import './core/init'; | ||
|
|
||
| module.exports = p5; | ||
| export default p5; |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
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:
- The built library can be imported using ES6 syntax (
import p5 from 'p5') - The built library can still be imported using CommonJS syntax (
const p5 = require('p5')) - 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.
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
npm run lintpasses