Esri / arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
https://developers.arcgis.com/arcgis-rest-js/
Apache License 2.0
347 stars 119 forks source link

Issue running demos on Windows (path/rootDir issue) #1140

Open hhkaos opened 10 months ago

hhkaos commented 10 months ago

Describe the bug

While trying to run npm start on Windows in the demo folders, which runs node ../../scripts/run-demo-server.js it throws an error in the following line: https://github.com/Esri/arcgis-rest-js/blob/main/scripts/get-package-json.js#L19

The problem is that the build path in rootDir has a semicolon (something like /D:/..), and it is causing an exception in Linux based shells like Gitbash.

Reproduction

You will probably need a Windows machine a follow any of the instructions (e.g. job demo instructions)

Logs

Sorry, I don't have them.

System Info

Windows 11.
It was this repo at this point, so ArcGIS REST JS Version: 4.1.4

Additional Information

Sorry, I can not provide more context. It was an easy fix, we just removed the semicolon locally, but I don't have time to submit a PR right now, but I wanted to at least issue this.

gavinr-maps commented 6 months ago

I do get an error when run:

cd demos/geocoder-browser
npm i
npm start

... on Windows 10 in Powershell.

The error I get:

> @esri/arcgis-rest-geocoder-vanilla@3.3.0 start
> node ../../scripts/run-demo-server.js

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
    at new NodeError (node:internal/errors:405:5)
    at validateString (node:internal/validators:162:11)
    at join (node:path:429:7)
    at getPackages (file:///C:/_work/arcgis-rest-js/scripts/get-package-json.js:19:37)
    at async file:///C:/_work/arcgis-rest-js/scripts/run-demo-server.js:7:20 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v18.17.1
npm ERR! Lifecycle script `start` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: @esri/arcgis-rest-geocoder-vanilla@3.3.0
npm ERR!   at location: C:\_work\arcgis-rest-js\demos\geocoder-browser

I agree with @hhkaos that we need to get the script at https://github.com/Esri/arcgis-rest-js/blob/main/scripts/get-package-json.js#L19 to be more Windows friendly.

COV-GIS commented 6 months ago

__dirname is not being constructed properly. The root should be the project directory not the full path of the project directory on disk.

import * as url from 'url';
import { readFile } from "fs/promises";
import { globby } from "globby";
import pkgDir from "pkg-dir";
import { join } from "path";

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

/**
 * Returns an object like:
 *
 * {
 *   packageName: package.json contents
 * }
 *
 * For all packages in the packages/* folder.
 */
export default async function getPackages() {
  const rootDir = await pkgDir(__dirname);
  const packageFiles = await globby(join(rootDir, "packages/*/package.json"));
  return Promise.all(
    packageFiles.map((pkgPath) => {
      return readFile(pkgPath).then((pkg) => {
        return JSON.parse(pkg);
      });
    })
  );
}