-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@arcgis/core: require() of ES modules is not supported. (Cannot import in Node.js app) #80
Comments
Hi Sandro, the JS API is ESM, not CJS. You have to use Node's native ESM support, or convert to CJS. Also note, we have a PR pending on this repo for a node sample. |
@andygup Thanks for the quick reply. I will have a look at the node examples once they are in. |
No plans for now since you can transpile the ES modules into the module type of your choice. Here's the link to the new node sample: https://github.com/Esri/feedback-js-api-next/tree/master/esm-samples/jsapi-node |
@andygup I wanted to give some more feedback on this one. I was able to get Native modules don't work for us because we still have some older node versions on our build systems. It took me a while but I got it working in the end. However, there are a couple of issues that make the whole process not ideal. Bundler overheadAdding rollup and a transpile step is a big overhead. We don't use a bundler, it's a pure Node.js/Typescript app, so adding a bundler just for the JS API is not ideal. TypescriptAfter transpiling I do understand that Node.js is not a priority atm for the JS API, but it would be really nice if standard-things/esmBtw. I also tried this package https://github.com/standard-things/esm but no success there. Ran into a couple of issues as well, mainly this one: standard-things/esm#868 |
I'm a little unclear on where the issue may be. Since core has a Here is a sample building the node samples with TypeScript. |
@sandromartis any luck? |
@andygup Thanks for getting back to me. Rollup
We are not using a bundler for our app and would like to avoid having to run the whole app through a bundler just to get a single dependency (@arcgis/core) working. It is a bit cumbersome but it works now. 👍 standard-things/esmI also tried The only problem is that Jest doesn't play nicely with it, but there is an open issue to get that solved: standard-things/esm#706
But still, importing CommonJS modules directly from Have you guys looked at how arcgis-rest-js is doing it? Anyway, thanks for the help! 👍 |
The API is too large. It would double the on-disk size of the npm install and it's not something we plan to do. |
Okay, that explanation makes sense 👍 Better to keep the I guess this ticket can be closed then, thanks for the help 👍 |
TL:DR:
Looks like there are no CommonJS modules yet so that
@arcgis/core
can be used in Node.jsAre there any plans to add it?
Use case
Using the
geometryEngine
and other geometry features of the JS API in a Node.js application.Describe the bug
I'm trying to import
@arcgis/core
into a simple Typescript example and run it in Node.js.The typescript file compiles fine to Javascript but when running it either directly with Node or through
ts-node
I get an error:Framework and build tools
To Reproduce
Run
npx ts-node main.ts
with the following code snipped andpackage.json
/tsconfig.json
setup.Running first
npx tsc main.ts
and thennode main.js
produces the same result.main.ts
package.json
tsconfig.json
Additional context
It looks Typescript finds the imports and compiles just fine. But then the execution throws the error.
It does not matter if compiled and executed directly with
ts-node
or first compiled and then manually executed withnode
.I also tried importing
@arcgis/core
into another bigger Typescript/Node project encountering the same error.This project works otherwise fine with various kinds of ES6 libraries.
The text was updated successfully, but these errors were encountered: