# p5.colorGenerator doesn't work on newer versions of p5?

**URL:** <https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372>\
**Category:** Libraries\
**Created:** [November 30, 2026, 4:09pm UTC](https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372 "2026-11-30T16:09:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamliewehr](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@adamliewehr](https://discourse.processing.org/u/adamliewehr)\
**Post date:** [November 30, 2026, 4:09pm UTC](https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372/1 "2026-11-30T16:09:42Z")

</div>

I’ve been having trouble getting the p5.ColorGenerator library to work with newer versions of p5. Here is the code that actually does something:

There is more HTML than what is below, everything else is just boilerplate.

```javascript
let colorGen;

function setup() {
createCanvas(600, 200);
background(100);
colorGen = new ColorGenerator("#ffba06");

colorGen.getShades(5).forEach((shade, index) => {
fill(shade);
rect(index * 100, 0, 100, 100);
});
}

```

This is what [the repo](https://github.com/alexandru-postolache/p5.colorGenerator/tree/main)recommends same exact code down to the version number in the CDN link. This does work, but I’d like to use a newer version of p5 (preferably the newest), and even though the repo says “It works with p5.js 1.4 and later”, it doesn’t work. I think something must have broke with the introduction of p5 v2? That is the only thing I can think of as of now. Does anyone know of a workaround that I can try? Or, if someone has a better library that they use to generate color pallets, that would be good too.

Another related issue I’m having is when I try to use this library as a module. Here is the code:

HTML without boilerplate:

JS:

```javascript
import ColorGenerator from "https://cdn.jsdelivr.net/gh/alexandru-postolache/p5.colorGenerator@2.0.0/p5.colorGenerator.mjs";

```

All I’m doing is importing the module, and I get this error:

`Uncaught SyntaxError: The requested module './p5.colorGenerator.js' does not provide an export named 'default'`

Even weirder, I get the same **exact** error when I use the named import syntax:

```javascript
import { ColorGenerator } ... 

```

It still tells me that The requested module ‘./p5.colorGenerator.js’ does not provide an export named ‘default’, even though I’m using the named import syntax.

I also posted something similar on the repo as [an issue](https://github.com/alexandru-postolache/p5.colorGenerator/issues/5#issuecomment-7283804003).

Thanks!

---

<div class="post-metadata">

**Author:** ![adamliewehr](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@adamliewehr](https://discourse.processing.org/u/adamliewehr)\
**Post date:** [November 30, 2026, 7:10pm UTC](https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372/2 "2026-11-30T19:10:57Z")

</div>

Follow up:

I’m 99% sure that it has something to do with changes that were implemented in p5 v2. I’ve tried the different combinations below:

p5 v2.4.0 (latest release) - doesn’t work

p5 v2.0.0 - doesn’t work

p5 v1.11.11 (one of the last 1.x releases) - **does** work

p5 v1.9.4 (the one in the libraries documentation) - **does** work

```auto
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/2.4.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/2.0.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.11/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/p5.js"></script>

<script src="https://cdn.jsdelivr.net/gh/alexandru-postolache/p5.colorGenerator@2.0.0/p5.colorGenerator.js"></script>

```

I am testing this by leaving one of the p5 CDN links uncommented, and running it with the following js code:

```javascript
let colorGen;
function setup() {
createCanvas(600, 200);
background(100);
circle(300, 100, 50);

colorGen = new ColorGenerator("#ffba06");
colorGen.getShades(5).forEach((shade, index) => {
fill(shade);
rect(index * 100, 0, 100, 100);
});
}

```

When I switch to a 2.x release of p5, I get this error message:

`p5.colorGenerator.js:191 Uncaught (in promise) Error: ColorGenerator requires p5. In instance mode, pass the sketch: new ColorGenerator(color, p).`

I get the same pattern as above when I use this code (instance mode):

```javascript
let colorGen;
const sketch = new p5(function (p) {
p.setup = function () {

p.createCanvas(600, 200);
p.background(100);
p.circle(p.width / 2, p.height / 2, 50);

colorGen = new ColorGenerator("#ffba06", p);
colorGen.getShades(5).forEach((shade, index) => {
  p.fill(shade);
  p.rect(index * 100, 0, 100, 100);
});
};
});

```

I get the same error as before when I use the code right above this.

The function below in p5.colorGenerator.js seems to be the issue. But I do not yet have the expertise to solve this problem.

```javascript
function resolveP5(instance) {
if (isP5Instance(instance)) return instance;
var root = typeof globalThis !== "undefined" ? globalThis : null;
if (root && root.p5 && isP5Instance(root.p5.instance)) return root.p5.instance;
if (isP5Instance(root)) return root;
throw new Error("ColorGenerator requires p5. In instance mode, pass the sketch: new ColorGenerator(color, p).");
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 30, 2026, 8:59pm UTC](https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372/3 "2026-11-30T20:59:58Z")

</div>

> <https://github.com/alexandru-postolache/p5.colorGenerator/issues/5>
>
> I'm not sure what I'm doing wrong, or if anyone else is having this issue, but I… just cannot seem to get this package to work no matter what I do. I've tried instance mode, using modules, and everything else and nothing seems to work. I get this error: 
> 
> \`Error: ColorGenerator requires p5. In instance mode, pass the sketch: new ColorGenerator(color, p).
> \`
> Even though I am literally using the example from the repo below: 
> 
> \`\`\`
> const sketch = (p) =\> {
> let colorGen;
> p.setup = () =\> {
> p.createCanvas(600, 200);
> p.background(100);
> colorGen = new ColorGenerator("#ffba06", p);
> // colorGen = p.createColorGenerator("#ffba06");
> };
> };
> new p5(sketch);
> \`\`\`
> 
> I know my HTML and js files are connected because I try adding other code (like just simple console logs) and it works just fine. 
> 
> I also try using modules, and that doesn't work either. I get this error: 
> 
> \`Uncaught SyntaxError: The requested module './p5.colorGenerator.js' does not provide an export named 'default'
> \`
> Even though in the p5.colorGenerator.mjs file I see these two lines. 
> 
> \`\`\`
> export { ColorGenerator };
> export default ColorGenerator;
> \`\`\`
> 
> I tried just straight up running the p5.colorGenerator.mjs and p5.colorGenerator.js files to see what was actually being exported, and after console.loging the ColorGenerator I get this: 
> 
> \`\`\`
> \<ref \*1\> \[class ColorGenerator\] {
> attachToP5: \[Function (anonymous)\],
> ColorGenerator: \[Circular \*1\],
> default: \[Circular \*1\]
> }
> \`\`\`
> 
> So, clearly something is being exported from the .mjs file, but for some reason it is not being exported. 
> 
> Lastly, when I just simply try and run the .js file below with node, i get the error that follows: 
> 
> \`\`\`
> import ColorGenerator from "../../otherLibs/p5.colorGenerator/p5.colorGenerator.mjs"; // this is the relative path. i've also tried the absolute path, which I checked both of them several times
> console.log(new ColorGenerator("#ffba06"));
> \`\`\`
> 
> this is the error:
> 
> \`throw new Error("ColorGenerator requires p5. In instance mode, pass the sketch: new ColorGenerator(color, p).");
> \`
> 
> Which is weird since I'm not in instance mode. Maybe I'm just being an idiot, but I really don't know what I'm doing wrong at this point. I feel like I've checked everything there is to check. I would appreciate any help, thanks.

Found out the culprit:

> <https://github.com/alexandru-postolache/p5.colorGenerator/blob/2.0.0/p5.colorGenerator.js#L117-L123>

Function **isP5Instance()** expects to find protected property _\_colorMaxes_.

However, p5js v2 seems to be using `_renderer.states.colorMaxes` instead.

So I believe you’re stuck w/ p5js v1:  
[https://Unpkg.com/p5@1](https://Unpkg.com/p5@1)  
[https://cdn.JSDelivr.net/npm/p5@1](https://cdn.JSDelivr.net/npm/p5@1)

---

<div class="post-metadata">

**Author:** ![adamliewehr](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@adamliewehr](https://discourse.processing.org/u/adamliewehr)\
**Post date:** [November 30, 2026, 11:23pm UTC](https://discourse.processing.org/t/p5-colorgenerator-doesnt-work-on-newer-versions-of-p5/50372/4 "2026-11-30T23:23:30Z")

</div>

Thanks for the information! So if I change all \_colorMaxes to \_renderer.states.colorMaxes, it would work? I’m assuming it would be much more complicated than that, but I thought I’d ask anyway. Based on what you know, do you think that the whole p5.colorGenerator library needs an overhaul?

I did find [this](https://dev.to/limzykenneth/designing-an-addon-library-system-for-p5js-20-3d4p)article. Would going through this and making the necessary changes be enough? Also, do you know of any other libraries that do this? I know of p5.pallet, but p5.colorGenerator is much more comprehensive. Also, I’m pretty sure p5.pallet has the same version issues as p5.colorGenerator as seen in [this issue](https://github.com/remistura/p5.palette/issues/26).

I wouldn’t mind trying to update this library for v2 since I think it would be super useful. Although, I will say, it is one of the less popular libraries (just based on number of stars on Github and how much I’ve heard about it). Do you have any insight into how designers choose color pallets for their art? Do they just do it by hand, or am I missing something?
