-
Notifications
You must be signed in to change notification settings - Fork 543
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
Error: require ESM modules with relative paths #613
Comments
I've just noticed that even with an valid absolute path to my script I get really strange errors: with the script poly.mjs export const polygon = function () {
return {
type: "FeatureCollection",
features: [{
type: "Feature",
geometry: { type: "Point", coordinates: [125.6, 10.1] },
properties: { name: "Dinagat Islands" }
}]
}
} mapshaper `
-rectangle bbox="-180,-90,180,90" `
-require "file:///C:/myProj/poly.mjs" `
-run "target.geojson = polygon()"
mapshaper `
-rectangle bbox="-180,-90,180,90" `
-require "file:///C:/myProj/poly.mjs" `
-run "polygon()"
|
Thanks for reporting this... the problem was evidently caused by my switching from I'll work on a fix asap. |
I published the fix given in the above-linked issue (using pathToFileURL() to convert absolute paths to file URLs). Please let me know if you still get errors -- I don't currently have a way to test on Windows. |
I've just tested
It now looks in the installation folder of the global mapshaper installation... |
Hmm.. I'm going to install Parallels so I can run Windows and test this properly... if that fails I might go back to using |
🤦♂️ I'm so sorry wasting your time on this. My paths changed after I moved the scripts around. |
Well, at least I got my Windows test environment set up ;) I also published another version without the following lines, which I thought might have been responsible for the problem: mapshaper/src/commands/mapshaper-require.mjs Lines 23 to 25 in 578879a
(mapshaper was converting relative paths to absolute paths, because
|
I'm glad you were able to find something positive in it. |
I've just updated to the latest version and I faced problems using
require
on a local script.mapshaper -require "./myESM.mjs"
mapshaper -require "./myCommon.js"
both result in an Error:
Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
only the following works:
mapshaper -require "file:///C:/myProj/myESM.mjs"
mapshaper -require "file:///C:/myProj/myCommon.js"
I think the problem is here https://github.com/mbloch/mapshaper/blob/master/src/commands/mapshaper-require.mjs#L24
It changes the relative to an absolute path but misses to add the required
file:///
I'm working on Windows (in case that makes a difference). I've testet Node 18 and 20 LTS
The text was updated successfully, but these errors were encountered: