mattdesl / canvas-sketch

[beta] A framework for making generative artwork in JavaScript and the browser.
MIT License
5.02k stars 393 forks source link

Two.js template error #156

Closed cdaein closed 2 years ago

cdaein commented 2 years ago

Trying to use the default two.js template by running:

canvas-sketch sketch.js --new --template=two --open 

gives an error:

Uncaught (in promise) TypeError: Two is not a constructor
    at sketch (sketch.js? [sm]:11:1)
    at SketchManager.js:967:20

There must have been some changes in two.js 0.8.x upgrade because the sketch runs fine with two.js 0.7.x. I am tagging the two.js creator just in case - @jonobr1

jonobr1 commented 2 years ago

I'm not in front of my computer right now, but I think this could be ES6 imports changing things. The import line might need to be:

const Two = require('two').default;

I'll check and if is the case I'll make a PR.

jonobr1 commented 2 years ago

It was actually an issue with how the build systems changed (from Rollup to esbuild). I just made a patch for it here: https://github.com/jonobr1/two.js/issues/643

You can install the latest npm version, v0.8.10 and it should be resolved. Thanks for sharing! You'll import as you did:

const Two = require('two.js');
cdaein commented 2 years ago

I can confirm it works with two.js 0.8.10 on my end. Thank you very much for the quick fix, and thank you for the beautiful library! 🙏