You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm on Node.js 20 with typescript, when try to use geoserver-node-client I see this error into the console
Error [ERR_REQUIRE_ESM]: require() of ES Module \[email protected]\node_modules\node-fetch\src\index.js from \[email protected]\node_modules\geoserver-node-client\dist\src\layer.js not supported.
Instead change the require of index.js in \[email protected]\node_modules\geoserver-node-client\dist\src\layer.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (\[email protected]\node_modules\geoserver-node-client\dist\src\layer.js:12:41) {
code: 'ERR_REQUIRE_ESM'
}
node-fetch is an ESM-only module - you are not able to import it with require. We recommend you stay on v2 which is built with CommonJS unless you use ESM yourself. We will continue to publish critical bug fixes for it.
If you want to require it, then downgrade to v2.
The other option you have is to use async import('node-fetch'), eg.:
/** * Get the GeoServer version. * * @throws Error if request fails * * @returns {Object} The version of GeoServer */asyncgetVersion(){consturl=this.url+'about/version.json';constresponse=await(awaitimport('node-fetch')).default(url,{credentials: 'include',method: 'GET',headers: {Authorization: this.auth}});if(!response.ok){constgeoServerResponse=awaitgetGeoServerResponseText(response);thrownewGeoServerResponseError(null,geoServerResponse);}returnresponse.json();}
Hi @cesco69 , thanks for your issue, your analysis and your workarounds 👍 Do you think this is only TypeScript related? Not really, or what do you think?
I have to dig a bit to fully understand whats going on and think what could be the best solution for this. I'll come back to this...
Hi, I'm on Node.js 20 with typescript, when try to use geoserver-node-client I see this error into the console
From the node-fetch package readme:
If you want to require it, then downgrade to v2.
The other option you have is to use async
import('node-fetch')
, eg.:or use CommonJS https://github.com/node-fetch/node-fetch?tab=readme-ov-file#commonjs eg.:
The workaround for use latest
geoserver-node-client
is install oldnode-fetch
2.6.8:The text was updated successfully, but these errors were encountered: