Giter VIP home page Giter VIP logo

Comments (10)

mbloch avatar mbloch commented on May 28, 2024 1

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:

if (moduleFile && !require('path').isAbsolute(moduleFile)) {
moduleFile = require('path').join(process.cwd(), moduleFile);
}

(mapshaper was converting relative paths to absolute paths, because require() didn't work correctly with some relative paths).

import() seems to work correctly with various forms of relative paths, so it's no longer necessary to convert to absolute paths.

from mapshaper.

indus avatar indus commented on May 28, 2024 1

I'm glad you were able to find something positive in it.
But I would prefer to close the issue in shame 😄

from mapshaper.

indus avatar indus commented on May 28, 2024

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()"

Error: [i] File not found (target.geojson)

mapshaper `
-rectangle bbox="-180,-90,180,90" `
-require "file:///C:/myProj/poly.mjs" `
-run "polygon()"

Error: [i] File not found (polygon())

from mapshaper.

mbloch avatar mbloch commented on May 28, 2024

Thanks for reporting this... the problem was evidently caused by my switching from require() to import(). This was in order to support ES modules in addition to Node modules. The new code worked fine on my Mac, but I see that import() fails on Windows using absolute paths, and according to the Node docs import() is not supposed to work with absolute paths. This issue clarifies things: nodejs/node#31710

I'll work on a fix asap.

from mapshaper.

mbloch avatar mbloch commented on May 28, 2024

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.

from mapshaper.

indus avatar indus commented on May 28, 2024

I've just tested 0.6.58 but had no luck with relative paths:
mapshaper -require "./myScript.js"

[require] Unable to load external module: Cannot find module 'C:\Users\...\AppData\Roaming\nvm\v18.17.1\node_modules\mapshaper\myScript.js' ...

It now looks in the installation folder of the global mapshaper installation...

from mapshaper.

mbloch avatar mbloch commented on May 28, 2024

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 require()

from mapshaper.

mbloch avatar mbloch commented on May 28, 2024

I haven't been able to reproduce the Unable to load external module error yet... I tested with mapshaper 0.6.58 on Windows 11 (running in Parallels) using both Node 18 and Node 20 in cmd.exe. -require works in 0.6.58 and throws the error you first reported in 0.6.57. Here's a screengrab:
image

Do you have any ideas that might help me reproduce your error? Are you using a different shell than cmd.exe?

from mapshaper.

mbloch avatar mbloch commented on May 28, 2024

-require works in powershell too, in my current setup:
image

from mapshaper.

indus avatar indus commented on May 28, 2024

🤦‍♂️ I'm so sorry wasting your time on this. My paths changed after I moved the scripts around.
I only realized after I tested it on a different laptop. So I guess only the initial error was valid.
Again - Sorry.

from mapshaper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.