<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Mocha and geometryEngine, SyntaxError: Cannot use import statement outside a module in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108195#M74980</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello! I'm using geometryEngine in my project and have been running into CJS Syntax issues when I rely on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;geometryEngine.&lt;/P&gt;&lt;P&gt;I've been reading through the mocha and babel docs and am having a difficult time figuring out what is wrong here. I suspect imports within the library may not be playing well with CJS.&lt;/P&gt;&lt;P&gt;I've simplified the issue to this example (the JS branch repros without TS):&lt;SPAN&gt;&amp;nbsp;&lt;A href="https://github.com/Jtfinlay/arcgis-import-problems/tree/js" target="_blank" rel="noopener"&gt;Jtfinlay/arcgis-import-problems at js (github.com)&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;When running&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;yarn test, I hit the following error:&lt;/P&gt;&lt;PRE&gt;$ mocha 'test/**/*.test.js'

D:\repos\repro\node_modules\@arcgis\core\geometry\geometryEngine.js:5
import{G as n}from"../chunks/geometryEngineBase.js";import{hydratedAdapter as e}from"./geometryAdapters/hydrated.js";function r(n){return Array.isArray(n)?n[0].spatialReference:n&amp;amp;&amp;amp;n.spatialReference}function t(e){return n.extendedSpatialReferenceInfo(e)}function u(t,u){return n.clip(e,r(t),t,u)}function i(t,u){return n.cut(e,r(t),t,u)}function o(t,u){return n.contains(e,r(t),t,u)}function c(t,u){return n.crosses(e,r(t),t,u)}function f(t,u,i){return n.distance(e,r(t),t,u,i)}function l(t,u){return n.equals(e,r(t),t,u)}function a(t,u){return n.intersects(e,r(t),t,u)}function s(t,u){return n.touches(e,r(t),t,u)}function p(t,u){return n.within(e,r(t),t,u)}function g(t,u){return n.disjoint(e,r(t),t,u)}function m(t,u){return n.overlaps(e,r(t),t,u)}function d(t,u,i){return n.relate(e,r(t),t,u,i)}function x(t){return n.isSimple(e,r(t),t)}function w(t){return n.simplify(e,r(t),t)}function E(t,u=!1){return n.convexHull(e,r(t),t,u)}function h(t,u){re

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:891:18)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Object.newLoader [as .js] (D:\repos\repro\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.&amp;lt;anonymous&amp;gt; (D:\repos\repro\src\/index.js:2:1)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Module._compile (D:\repos\repro\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.&amp;lt;anonymous&amp;gt; (D:\repos\repro\test\/example.test.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Module._compile (D:\repos\repro\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Object.newLoader [as .js] (D:\repos\repro\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.implementationOfRequireOrImportForUnstableEsm [as requireOrImport] (D:\repos\repro\node_modules\mocha\lib\nodejs\esm-utils.js:101:12)
    at Object.exports.loadFilesAsync (D:\repos\repro\node_modules\mocha\lib\nodejs\esm-utils.js:88:34)
    at Mocha.loadFilesAsync (D:\repos\repro\node_modules\mocha\lib\mocha.js:461:19)
    at singleRun (D:\repos\repro\node_modules\mocha\lib\cli\run-helpers.js:125:15)
    at exports.runMocha (D:\repos\repro\node_modules\mocha\lib\cli\run-helpers.js:190:10)
    at Object.exports.handler (D:\repos\repro\node_modules\mocha\lib\cli\run.js:374:11)
    at D:\repos\repro\node_modules\yargs\build\index.cjs:443:71
error Command failed with exit code 1.&lt;/PRE&gt;&lt;P&gt;Here is the yarn test command:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;test&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;mocha 'test/**/*.test.js'&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I also asked this question on stackoverflow:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/69564838/arcgis-js-import-geometryengine-syntaxerror-cannot-use-import-statement-outsi" target="_blank" rel="noopener"&gt;typescript - Arcgis js, import geometryEngine, SyntaxError: Cannot use import statement outside a module - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Appreciate any help!&lt;/P&gt;</description>
    <pubDate>Sat, 16 Oct 2021 17:59:42 GMT</pubDate>
    <dc:creator>jtfinlay</dc:creator>
    <dc:date>2021-10-16T17:59:42Z</dc:date>
    <item>
      <title>Mocha and geometryEngine, SyntaxError: Cannot use import statement outside a module</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108195#M74980</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello! I'm using geometryEngine in my project and have been running into CJS Syntax issues when I rely on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;geometryEngine.&lt;/P&gt;&lt;P&gt;I've been reading through the mocha and babel docs and am having a difficult time figuring out what is wrong here. I suspect imports within the library may not be playing well with CJS.&lt;/P&gt;&lt;P&gt;I've simplified the issue to this example (the JS branch repros without TS):&lt;SPAN&gt;&amp;nbsp;&lt;A href="https://github.com/Jtfinlay/arcgis-import-problems/tree/js" target="_blank" rel="noopener"&gt;Jtfinlay/arcgis-import-problems at js (github.com)&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;When running&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;yarn test, I hit the following error:&lt;/P&gt;&lt;PRE&gt;$ mocha 'test/**/*.test.js'

D:\repos\repro\node_modules\@arcgis\core\geometry\geometryEngine.js:5
import{G as n}from"../chunks/geometryEngineBase.js";import{hydratedAdapter as e}from"./geometryAdapters/hydrated.js";function r(n){return Array.isArray(n)?n[0].spatialReference:n&amp;amp;&amp;amp;n.spatialReference}function t(e){return n.extendedSpatialReferenceInfo(e)}function u(t,u){return n.clip(e,r(t),t,u)}function i(t,u){return n.cut(e,r(t),t,u)}function o(t,u){return n.contains(e,r(t),t,u)}function c(t,u){return n.crosses(e,r(t),t,u)}function f(t,u,i){return n.distance(e,r(t),t,u,i)}function l(t,u){return n.equals(e,r(t),t,u)}function a(t,u){return n.intersects(e,r(t),t,u)}function s(t,u){return n.touches(e,r(t),t,u)}function p(t,u){return n.within(e,r(t),t,u)}function g(t,u){return n.disjoint(e,r(t),t,u)}function m(t,u){return n.overlaps(e,r(t),t,u)}function d(t,u,i){return n.relate(e,r(t),t,u,i)}function x(t){return n.isSimple(e,r(t),t)}function w(t){return n.simplify(e,r(t),t)}function E(t,u=!1){return n.convexHull(e,r(t),t,u)}function h(t,u){re

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:891:18)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Object.newLoader [as .js] (D:\repos\repro\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.&amp;lt;anonymous&amp;gt; (D:\repos\repro\src\/index.js:2:1)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Module._compile (D:\repos\repro\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.&amp;lt;anonymous&amp;gt; (D:\repos\repro\test\/example.test.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Module._compile (D:\repos\repro\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Object.newLoader [as .js] (D:\repos\repro\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.implementationOfRequireOrImportForUnstableEsm [as requireOrImport] (D:\repos\repro\node_modules\mocha\lib\nodejs\esm-utils.js:101:12)
    at Object.exports.loadFilesAsync (D:\repos\repro\node_modules\mocha\lib\nodejs\esm-utils.js:88:34)
    at Mocha.loadFilesAsync (D:\repos\repro\node_modules\mocha\lib\mocha.js:461:19)
    at singleRun (D:\repos\repro\node_modules\mocha\lib\cli\run-helpers.js:125:15)
    at exports.runMocha (D:\repos\repro\node_modules\mocha\lib\cli\run-helpers.js:190:10)
    at Object.exports.handler (D:\repos\repro\node_modules\mocha\lib\cli\run.js:374:11)
    at D:\repos\repro\node_modules\yargs\build\index.cjs:443:71
error Command failed with exit code 1.&lt;/PRE&gt;&lt;P&gt;Here is the yarn test command:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;test&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;mocha 'test/**/*.test.js'&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I also asked this question on stackoverflow:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/69564838/arcgis-js-import-geometryengine-syntaxerror-cannot-use-import-statement-outsi" target="_blank" rel="noopener"&gt;typescript - Arcgis js, import geometryEngine, SyntaxError: Cannot use import statement outside a module - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Appreciate any help!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Oct 2021 17:59:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108195#M74980</guid>
      <dc:creator>jtfinlay</dc:creator>
      <dc:date>2021-10-16T17:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Mocha and geometryEngine, SyntaxError: Cannot use import statement outside a module</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108426#M74988</link>
      <description>&lt;P&gt;It looks like you're running this in a node environment with ESM.&lt;/P&gt;&lt;P&gt;Check out our &lt;A href="https://github.com/Esri/jsapi-resources/tree/master/esm-samples/jsapi-node" target="_self"&gt;node sample&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;You have a couple of options, but this would work.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Add "type": "module" to your package.json&lt;/LI&gt;&lt;LI&gt;Directory imports not allowed in node with esm, so you need `import callIIntoArcgis from '../src/index.js`&lt;/LI&gt;&lt;LI&gt;Add the ".js" extension to all your imports from "@arcgis/core"&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;That will get your tests and everything else working.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 14:46:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108426#M74988</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-10-18T14:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Mocha and geometryEngine, SyntaxError: Cannot use import statement outside a module</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108704#M75006</link>
      <description>&lt;P&gt;Thank you - no luck out of the gate with the three changes you listed, but I will debug through the `jsapi-node` resources for a bit and let you know if I make headway.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 04:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/mocha-and-geometryengine-syntaxerror-cannot-use/m-p/1108704#M75006</guid>
      <dc:creator>jtfinlay</dc:creator>
      <dc:date>2021-10-19T04:54:29Z</dc:date>
    </item>
  </channel>
</rss>

