简体   繁体   English

如何使用RequireJS加载CartoDb?

[英]How to load CartoDb using RequireJS?

When I try to require the CartoDb library it returns a script error and then tries to load it direct from the server. 当我尝试要求CartoDb库时,它返回脚本错误,然后尝试直接从服务器加载它。

Error: Script error for "cartodb", needed by: app
http://requirejs.org/docs/errors.html#scripterror

I've created a simple example here: https://github.com/JohnGale87/requirejs-cartodb-helloworld 我在这里创建了一个简单的示例: https : //github.com/JohnGale87/requirejs-cartodb-helloworld

Steps to replicate the issue: 复制问题的步骤:

1) Visit this page: https://rawgit.com/JohnGale87/requirejs-cartodb-helloworld/master/index.html 1)访问此页面: https : //rawgit.com/JohnGale87/requirejs-cartodb-helloworld/master/index.html

2) Open the console 2)打开控制台

3) See the error 3)看到错误

4) View the network tab and see a 404 error where cartodb.js was attempted to be loaded (even though it is already compiled into app.min.js) 4)查看“网络”选项卡,并在尝试加载cartodb.js的地方看到404错误(即使已将其编译到app.min.js中)

Am I doing something wrong when I define my script(s) or is the cartodb libary not compatible with RequireJS? 定义脚本时我做错什么了吗?还是cartodb库与RequireJS不兼容?

I have tried with and without a shim in my requirejs build config but I always get the same error. 我已经在我的requirejs构建配置中尝试了无垫片的情况,但是总是遇到相同的错误。

Issue raised here but I am half expecting them to say it is a RequireJS issue rather than a CartoDb issue. 这里提出问题但是我半心希望他们说这是RequireJS问题,而不是CartoDb问题。

Try to add param cartodb to use it in function body, like this: 尝试添加param cartodb以在函数体中使用它,如下所示:

define('app', ['module', 'jquery', 'cartodb'],
function(m, $, cartodb) { 
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM