Skip to content

[p5.js 2.0 Bug Report]: require('../../translations/dev') breaks ESM usage in browser-based tools like Vite #7822

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

Open
2 of 17 tasks
nakednous opened this issue May 15, 2025 · 0 comments
Labels
Internationalization Relates to 'src/core/internationalization.js' p5.js 2.0

Comments

@nakednous
Copy link
Contributor

nakednous commented May 15, 2025

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.0.2

Web browser and version

Firefox 138.0.3

Operating system

Archlinux

Steps to reproduce this

Steps:

  1. Create a modern frontend project (e.g., with Vite).
  2. Install p5 v2.0.2.
  3. Import with:
import p5 from 'p5'
  1. Run npm run dev.

Snippet:

import p5 from 'p5'

new p5(p => {
  p.setup = () => p.createCanvas(400, 400)
  p.draw = () => p.background('white')
})

Result:

Vite build fails immediately:

✘ [ERROR] Could not resolve "../../translations/dev"

node_modules/p5/lib/p5.esm.js:76212:36:
76212 │     let completeResources = require('../../translations/dev');

Cause:

The ESM build includes this CommonJS line:

// When the library is built in development mode ( using npm run dev )
// we want to use the current translation files on the disk, which may have
// been updated but not yet pushed to the CDN.
let completeResources = require('../../translations/dev');

This require() is invalid in ESM and unresolved in Vite/browser tools.

Note:

Manually replacing this line with let completeResources = {}; allows the build to proceed — but this is just a workaround, not a real fix.

@github-actions github-actions bot added the Internationalization Relates to 'src/core/internationalization.js' label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization Relates to 'src/core/internationalization.js' p5.js 2.0
Projects
None yet
Development

No branches or pull requests

1 participant