实习生4无法使用Dojo Loader和ArcGIS JavaScript API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实习生4无法使用Dojo Loader和ArcGIS JavaScript API相关的知识,希望对你有一定的参考价值。
Intern 4 Dojo加载程序无法在ArcGIS javascript API中找到Dojo库。有谁知道如何使用Dojo和ArcGIS JavaScript API制作最新版本的Intern?
old fix不再有效。实习生说:
PS C:UniServerZwwwHelloIntern2> .
ode_modules.binintern
Config has unknown option "useLoader"
(????)?????
ReferenceError: define is not defined
at Object.<anonymous> <testsunitViewByAttributeTest.js:1:63>
at Module._compile <module.js:652:30>
at Object.Module._extensions..js <module.js:663:10>
at Module.load <module.js:565:32>
at tryModuleLoad <module.js:505:12>
at Function.Module._load <module.js:497:3>
at Module.require <module.js:596:17>
at require <internalmodule.js:11:18>
at Node.loadScript <srclibexecutorsNode.ts:260:5>
at Node._loader <srcloadersdefault.ts:10:16>
此外,鉴于本文末尾的intern.json文件,实习生说:
PS C:UniServerZwwwHelloIntern2> .
ode_modules.binintern
(????)?????
Error: Cannot find module 'node_modules/dojo/dojo.js' from 'C:UniServerZwwwHe
lloIntern2'
at Function.module.exports [as sync] <node_modules
esolvelibsync.js:40:15>
at Node.loadScript <srclibexecutorsNode.ts:264:13>
at <srcloadersdojo.ts:17:15>
at Node.Executor.registerLoader <srclibexecutorsExecutor.ts:468:37>
at Object.<anonymous> <srcloadersdojo.ts:6:7>
at Module._compile <module.js:652:30>
at Object.Module._extensions..js <module.js:663:10>
at Module.load <module.js:565:32>
at tryModuleLoad <module.js:505:12>
at Function.Module._load <module.js:497:3>
intern.json:
{
"loader" : {
"script" : "dojo",
"options" : {
"packages" : [{
"name" : "zian",
"location" : "/zian"
}, {
"name" : "dgrid",
"location" : "http://js.arcgis.com/4.6/dgrid"
}, {
"name" : "dijit",
"location" : "http://js.arcgis.com/4.6/dijit"
}, {
"name" : "esri",
"location" : "http://js.arcgis.com/4.6/esri"
}, {
"name" : "dojo",
"location" : "http://js.arcgis.com/4.6/dojo"
}, {
"name" : "dojox",
"location" : "http://js.arcgis.com/4.6/dojox"
}, {
"name" : "moment",
"location" : "http://js.arcgis.com/4.6/moment"
}
]
}
},
"filterErrorStack" : false,
"suites" : ["tests/unit/*.js"],
"environments" : ["chrome", "node"]
}
最后,为了完整起见,这里是完整的目录结构:
app has: calc.js and index.js
js has: starter.js
node_module has: tons and tons of folder...
test has: unit has: ViewByAttributeTest.js
zian has: ViewByAttribute.js
root of the folder has the above folders and: index.html, index.js, intern.json, package.json, and package-lock.json
的package.json:
{
"name": "helloworldcdnapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node index.js"
},
"author": "Zian Choy",
"license": "ISC",
"dependencies": {
"intern": "^4.0.0-rc.1"
}
}
ViewByAttributeTest.js
define([
'require'
], function (require) {
var registerSuite = intern.getInterface('object').registerSuite;
var assert = intern.getPlugin('chai').assert;
registerSuite('ViewByAttribute', {
'default data': function () {
assert.strictEqual(1, 1, '1 is 1.');
}
});
});
顺便说一句,如果你读到这一点,我希望你能理解计算机中的幽默,而不是认识到1等于1。
答案
你需要做几件事才能让它发挥作用。首先,你需要添加一个自定义加载器来加载dojo
,然后你需要更改你的script
来引用intern.json
中的新dojo加载器文件。该文件看起来像:
intern.registerLoader(function(options) {
// do checks here
return intern.loadScript(<location of your dojo file in arcgis js api>)
.then(function() {
//do stuff here
})
});
另一答案
有一个文档可以解释在WebAppbuilder for ArcGIS上设置实习生4的过程。 WAB使用ArcGIS API for Javascript。
Best Practices for Unit Test on WAB
以上是关于实习生4无法使用Dojo Loader和ArcGIS JavaScript API的主要内容,如果未能解决你的问题,请参考以下文章