//index.ts
import * as p5 from "p5";
import "p5/lib/addons/p5.dom";
-How to solve the problem manually:
In node_modules/p5/lib/addons/p5.dom.js :
Cut lines 3325 to 3247 and paste at line 3324
Before:
// node_modules/p5/lib/addons/p5.dom.js
(function(root, factory) {
if (typeof define === 'function' && define.amd)
define('p5.dom', ['p5'], function(p5) {
factory(p5);
});
else if (typeof exports === 'object') factory(require('../p5'));
else factory(root['p5']);
})(this, function(p5) {
....
});
p5.File._createLoader = function(theFile, callback) {
var reader = new FileReader();
reader.onload = function(e) {
var p5file = new p5.File(theFile);
p5file.data = e.target.result;
callback(p5file);
};
return reader;
};
p5.File._load = function(f, callback) {
// Text or data?
// This should likely be improved
if (/^text\//.test(f.type)) {
p5.File._createLoader(f, callback).readAsText(f);
} else if (!/^(video|audio)\//.test(f.type)) {
p5.File._createLoader(f, callback).readAsDataURL(f);
} else {
var file = new p5.File(f);
file.data = URL.createObjectURL(f);
callback(file);
}
};
After:
// node_modules/p5/lib/addons/p5.dom.js
(function(root, factory) {
if (typeof define === 'function' && define.amd)
define('p5.dom', ['p5'], function(p5) {
factory(p5);
});
else if (typeof exports === 'object') factory(require('../p5'));
else factory(root['p5']);
})(this, function(p5) {
....
p5.File._createLoader = function(theFile, callback) {
var reader = new FileReader();
reader.onload = function(e) {
var p5file = new p5.File(theFile);
p5file.data = e.target.result;
callback(p5file);
};
return reader;
};
p5.File._load = function(f, callback) {
// Text or data?
// This should likely be improved
if (/^text\//.test(f.type)) {
p5.File._createLoader(f, callback).readAsText(f);
} else if (!/^(video|audio)\//.test(f.type)) {
p5.File._createLoader(f, callback).readAsDataURL(f);
} else {
var file = new p5.File(f);
file.data = URL.createObjectURL(f);
callback(file);
}
};
});
Welcome! 馃憢 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.
I realized that I was using an older version of p5.js :/ sorry folks for the false alarm!
Actually, I have this exact problem. My file starts with the lines:
import p5 from "p5";
import 'p5/lib/addons/p5.sound';
I use Laravel Mix for minifying + compiling ES6 down to vanilla JS.
Since I've moved from 0.7.2 to 1.0.0 (NPM version), the compiled script that uses those lines gives me a "ReferenceError: p5 is not defined" for line 3112 of p5.sound - "p5.prototype.isSupported = ...". Any hints?
Running into the same issue as @vanyamil with Typescript and Webpack
import p5 from "p5"
import "p5/lib/addons/p5.sound"
Same, webpack + p5 seems tricky.
Most helpful comment
Actually, I have this exact problem. My file starts with the lines:
import p5 from "p5";
import 'p5/lib/addons/p5.sound';
I use Laravel Mix for minifying + compiling ES6 down to vanilla JS.
Since I've moved from 0.7.2 to 1.0.0 (NPM version), the compiled script that uses those lines gives me a "ReferenceError: p5 is not defined" for line 3112 of p5.sound - "p5.prototype.isSupported = ...". Any hints?