"ReferenceError: document is not defined" occurred when generate custom build of API

6153
1
03-18-2018 10:57 PM
nie
by
New Contributor II

I'm following this instruction(Using Bower for Custom Builds | ArcGIS API for JavaScript 4.6 ) to generate a custom build(RequireJS) of API, but this error occured:

Running "requirejs:single" (requirejs) task
ReferenceError: document is not defined
In module tree:
dojo/NodeList-dom
dojo/dom-construct
dojo/dom-attr
dojo/dom-prop
dojo/_base/connect
dojo/on
dojo/has

{ Error: ReferenceError: document is not defined
In module tree:
dojo/NodeList-dom
dojo/dom-construct
dojo/dom-attr
dojo/dom-prop
dojo/_base/connect
dojo/on
dojo/has

at /Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:28326:19
at /Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:3059:39
at /Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:2999:25
at Function.prim.nextTick (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:28077:9)
at Object.errback (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:2998:26)
at Object.callback (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:2984:23)
at Object.then (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:3038:23)
at build (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:28283:12)
at runBuild (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:30291:17)
at Object.execCb (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:1426:22)
at Module.init (/Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:1038:26)
at /Users/Nie/custom-jsapi/4.x/bower/requirejs/node_modules/requirejs/bin/r.js:1710:36
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

I'm working on a Mac and installed these tools:

➜ requirejs git:(master) ✗ node --version
v9.1.0
➜ requirejs git:(master) ✗ git --version
git version 2.10.1
➜ requirejs git:(master) ✗ grunt --version
grunt-cli v1.2.0
grunt v1.0.2
➜ requirejs git:(master) ✗ bower --version
1.8.2
➜ requirejs git:(master) ✗ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

After git clone from GitHub, I have executed 'npm install' and added these lines at the top of app/main.js:

var dojoConfig = {
baseUrl: '.',
packages: [
'app',
'dijit',
'dojo',
'dojox',
'dstore',
'dgrid',
'esri'
]
};

Then this error occurred when execute 'npm run build'.

Anyone has some clues?

Tags (2)
0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor

At this point I don't think it's viable to be able to use RequireJS optimizer to build 4x. It should still work fine in 3x, but there are too many pieces in 4x that reference the document property right now to make it work.

In the error above you need to add dojo/dom-construct to the list of excluded features. But then you may hit another error that will require you to add more files to the list of excluded features and the number of files that will be required to dynamically load will just grow.

The Dojo build works fine, but RequireJS does not have the tooling that the Dojo build system has to work around this particular issue.

With some new tooling we're adding in as well, I don't think RequireJS optimizer can continue to be a build target for 4x.

0 Kudos