MegaPixImage Error From FineUploader When Loading Page with RequireJS

大兔子大兔子 提交于 2019-12-13 07:35:16

问题


I am refactoring my application to use RequireJS (using the sbt-web abstraction in Play Framework, but that isn't germane).

First, I simply sought to use a shim to load FineUploader since it isn't AMD-compatible, but I encountered a "MegaPixImage is not defined" error. That seemed weird to me since FineUploader has no dependencies (as third-party stuff is built-in).

But after seeing this Stack Overflow post, I downloaded the library separately and set up my RequireJS configuration this way (in CoffeeScript):

requirejs.config(
  paths:
    megapiximage: './megapiximage'
    fineUploader: './custom.fineuploader'
  shim:
    fineUploader:
      exports: 'fineUploader'
      deps: ['jquery', 'megapiximage' ]
)

require(['./main'], (main) ->
  require(['fineUploader', './myfile'])

  return
)

However, I still get the same error even though the library is AMD-compatible.

Any insight into how I should set up my RequireJS configuration is appreciated.


回答1:


The FineUploader package references the 'MegaPixImage' variable, so you need to make that available. I think the following should work:

require(['fineUploader', 'megapiximage'], function(fineUploader, MegaPixImage) {
    // initialize your fineuploader here
})

Note that you have actually included the MegaPixImage library twice now. I therefore decided to keep FineUploader out of my RequireJS setup and add it as a seperate javascript file in the HTML.



来源:https://stackoverflow.com/questions/24983663/megapiximage-error-from-fineuploader-when-loading-page-with-requirejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!