CreateJS / PreloadJS

PreloadJS makes preloading assets & getting aggregate progress events easier in JavaScript. It uses XHR2 when available, and falls back to tag-based loading when not.

Home Page:http://createjs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught ReferenceError: createjs is not defined

rifkegribenes opened this issue · comments

Hi, I am trying to figure out how to get preloadjs and soundjs to work together in a React project. I had preloadjs working ok on its own when I was importing it from this npm package: https://www.npmjs.com/package/preload-js

But then I found out that the npm package includes an outdated version of preloadjs which is not compatible with the newer version of soundjs which I had downloaded directly from github (https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js). And as far as I know there are not npm packages available for the most updated versions of these scripts -- they just have to be downloaded from github and used as-is (let me know if I'm missing something here).

So now I have downloaded the most recent versions of both files from github. (using preloadjs downloaded from here: https://github.com/CreateJS/PreloadJS/blob/master/lib/preloadjs.js) But when I try to import preloadjs like this to create a load queue:

import createjs from './preloadjs';

I'm getting the following error:

Uncaught ReferenceError: createjs is not defined
    at preloadjs.js:45
    at Object.<anonymous> (preloadjs.js:63)
    at Object../src/utils/preloadjs.js (preloadjs.js:7896)
    at __webpack_require__ (bootstrap 5aa5aea4a716276089e1:659)
    at fn (bootstrap 5aa5aea4a716276089e1:85)
    at Object../src/utils/asset_loader.js (asset_loader.js:1)
    at __webpack_require__ (bootstrap 5aa5aea4a716276089e1:659)
    at fn (bootstrap 5aa5aea4a716276089e1:85)
    at Object../src/App.jsx (log-apply-result.js:30)
    at __webpack_require__ (bootstrap 5aa5aea4a716276089e1:659)

what am I doing wrong?

Createjs v1 doesn't officially support using import or require. Support is coming in v2. Until then you'll need to import the scripts using good ol' <script /> tags. You can either grab a direct copy from github, or use a cdn. Our official cdn; http://code.createjs.com/ or third parties like https://cdnjs.com/libraries/PreloadJS or https://www.jsdelivr.com/package/npm/preloadjs are all good options.

Another option, since your using WebPack, you can also try imports-loader

Hopefully thank helps!