diff --git a/src/core/init.js b/src/core/init.js index 764437b1ff..78f93656e9 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -16,7 +16,7 @@ export const _globalInit = () => { // Could have been any property defined within the p5 constructor. // If that property is already a part of the global object, // this code has already run before, likely due to a duplicate import - if (typeof window._setupDone !== 'undefined') { + if (typeof window.p5 !== 'undefined') { console.warn( 'p5.js seems to have been imported multiple times. Please remove the duplicate import' ); diff --git a/src/core/main.js b/src/core/main.js index a5c9a6c93d..8d571b06e5 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -125,11 +125,17 @@ class p5 { // If the user has created a global setup or draw function, // assume "global" mode and make everything global (i.e. on the window) if (!sketch) { + if (typeof window.p5 !== 'undefined') { + console.warn('p5.js appears to have been imported multiple times. This could cause errors.'); + return; + } this._isGlobal = true; + window._p5Instance = this; if (window.hitCriticalError) { return; } p5.instance = this; + window.p5 = p5; // Loop through methods on the prototype and attach them to the window // All methods and properties with name starting with '_' will be skipped