tomwayson / esri-require-js

Example of how to load Esri AMD modules using RequireJS - DEPRECATED
2 stars 0 forks source link

dojo is not defined #1

Closed shuai-zh closed 10 years ago

shuai-zh commented 10 years ago

I tried your sample but got this error:

Resource interpreted as Script but transferred with MIME type text/plain: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback". script.js:38
Uncaught ReferenceError: dojo is not defined MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback:1

Should I add dojo as one of the dependencies?

tomwayson commented 10 years ago

Did you first run the bower install? It's listed as a dependency in bower.json:

https://github.com/tomwayson/esri-require-js/blob/master/bower.json

Tom

shuai-zh commented 10 years ago

Yes, I installed all the bower components, the error was thrown from the jsonp callback of the ArcGIS Server, I think the dojo object was not in the 'window' scope, however when I manually add the dojo dependency and expose the dojo object to window.dojo in main.js, some other error just occurs.

Are you sure your codes still work now?

Please help me with it, thanks.

从我的android设备发送。

-----Original Message----- From: Tom Wayson notifications@github.com To: tomwayson/esri-require-js esri-require-js@noreply.github.com Cc: Nicolas Zhang nicolasloco@gmail.com Sent: 星期五, 18 4月 2014 3:31 Subject: Re: [esri-require-js] dojo is not defined (#1)

Did you first run the bower install? It's listed as a dependency in bower.json:

https://github.com/tomwayson/esri-require-js/blob/master/bower.json

Tom


Reply to this email directly or view it on GitHub: https://github.com/tomwayson/esri-require-js/issues/1#issuecomment-40753284

tomwayson commented 10 years ago

You are correct. I just tried cloning and installing on a new machine and I see the same error.

At first I thought it was the dojo version, but it turned out to be the requirejs version (2.1.11) that was causing the issue. To get it working, use bower to uninstall 2.1.11, get the latest bower.json and then install 2.1.8 by running bower install again.

This should give you a good idea of how unstable this code is. I should put a bigger warning in the README. Besides the fact that this is not a supported way to use the Esri JS API, I can't even say I'd recommend it.

shuai-zh commented 10 years ago

@tomwayson Thanks for your effort, that really works for me.

And the reason why we tried to combine Require.js and ArcGIS API for JavaScript is that we already built our app with Require.js and Angular.js, we do not want to break our architecture in order to leverage the map things. I think that ESRI should really think about decouple its JS API with dojo for there may be lots of people who do not use dojo either, I think.

BTW, is there any known issue you would like to share when combining these two frameworks, as you mentioned that you would not recommend it?

tomwayson commented 10 years ago

There were some good examples of how to integrate the Esri JS API w/ Angular demoed at the recent Esri DevSummit. You can see the videos and repos here:

@patrickarlt's Example of how to get the 2 libraries to work together and write directives: video (start around 23 min) repo

@mpriour expands on the above example by adding more events and updating other parts of the UI outside the map: repo

FYI - as far as I know, there are no plans to decouple the Esri API from Dojo. That said, there are a lot of efforts within Esri to demonstrate how to integrate our APIs w/ other frameworks. If all you need to do is add some Esri map services to a map on a page w/ simple navigation, you might also look into the Esri leaflet plugin (if you haven't already).

patrickarlt commented 10 years ago

@chocstarfish I'll chime in here too.

The JS API doesn't support Require JS in any way shape or form. The problem is mostly with the slightly different implementations of the AMD spec especially plugins.

There is some good news...

  1. You could switch to using Dojos AMD loader and plugins and drop Require JS. If you are only using the JS API in one small section of your application this probably isn't practical. In my examples with Angular JS I'm using the AMD loader from Dojo. It might be impractical but it is the most stable option.
  2. Take a look at the Esri Leaflet plugin (which I maintain). Its not as fully featured as the JS API but has a lot of nice features and is improving rapidly. I gave a talk on it at Dev Summit here is the video and slides
  3. Continue using the examples that @tomwayson has laid out here understanding that they are experimental and you might run into issues and you cant update RequireJS.

I agree that those aren't the most attractive options. But for integrating into a large existing application those are probably your options.

Maybe @mpriour can comment. I know he has done some work on this.

mpriour commented 10 years ago

Praveen Ponnusamy has been working to alter some build options and configuration settings to allow RequireJS to work properly with the esri js api. These changes made it in to the 3.9 version of the api. I believe he is working on a blog post to demonstrate the correct usage and configuration required.

peluja1012 commented 10 years ago

@mpriour Do you know if Praveen Ponnusamy published the blog post showing how to get RequireJS to work properly with the esri api? Our team wants to leverage the api but we also can't change our RequireJS based architecture at this point.