gtfs-to-geojson icon indicating copy to clipboard operation
gtfs-to-geojson copied to clipboard

types cannot be installed

Open Joe-ChenZ opened this issue 2 years ago • 7 comments

import gtfsToGeoJSON from 'gtfs-to-geojson'; generates an error The suggested fix in VSCode is to do add the type. Our project doesn't use npm, so i use yarn add.

When I do: yarn add @types/gtfs-to-geojson yarn add v1.22.10 warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/4] Resolving packages... error An unexpected error occurred: "https://registry.yarnpkg.com/@types%2fgtfs-to-geojson: Not found".

I am using Typescript. Is it not supported?

Joe-ChenZ avatar Jul 20 '22 01:07 Joe-ChenZ

This library doesn't have types defined yet.

I made add this sometime in the same way types are defined in node-gifs: https://github.com/BlinkTagInc/node-gtfs/tree/master/%40types

What is the error you get when importing import gtfsToGeoJSON from 'gtfs-to-geojson'; ?

brendannee avatar Jul 20 '22 05:07 brendannee

Could not find a declaration file for module 'gtfs-to-geojson'. 'C:/Users/Joech/GTComputing/Summer 2022 intern/react-rider/node_modules/gtfs-to-geojson/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/gtfs-to-geojson if it exists or add a new declaration (.d.ts) file containing declare module 'gtfs-to-geojson';

5 import gtfsToGeoJSON from 'gtfs-to-geojson'; ~~~~~~~~~~~~~~~~~

at createTSError (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:859:12)
at reportTSError (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:863:19)
at getOutput (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1077:36)
at Object.compile (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1433:41)
at Module.m._compile (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .tsx] (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {

diagnosticCodes: [ 7016 ] }

Joe-ChenZ avatar Jul 20 '22 17:07 Joe-ChenZ

Since types are not defined for this module yet, you can ignore that error.

If you want to hide it, try: https://stackoverflow.com/a/55576119/363155

brendannee avatar Jul 20 '22 17:07 brendannee

I was wondering if i can use this module alternatively https://github.com/BlinkTagInc/node-gtfs

Joe-ChenZ avatar Jul 20 '22 18:07 Joe-ChenZ

Yes, you can use https://github.com/BlinkTagInc/node-gtfs to import and query GTFS, it is a more low-level library than gtfs-to-geojson

brendannee avatar Jul 20 '22 18:07 brendannee

C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers>ts-node FutureRouteProvider.tsx C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:851 return old(m, filename); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\node_modules\gtfs\index.js from C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx not supported. Instead change the require of index.js in C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx to a dynamic import() which is available in all CommonJS modules. at Object.require.extensions. [as .js] (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:851:20) at Object. (C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx:3:16) at Module.m._compile (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:857:29) at Object.require.extensions. [as .tsx] (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:859:16) at phase4 (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:466:20) at bootstrap (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:54:12) at main (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:33:12) at Object. (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:579:5) { code: 'ERR_REQUIRE_ESM' }

I followed the example code and did this, but it generates an error:


import { importGtfs } from 'gtfs';

// import gtfsToGeoJSON from 'gtfs-to-geojson';
import { readFile } from 'fs/promises';


import { util } from "protobufjs";
const TRIP_UPDATES_URL = 'https://gtfs-rt.itsmarta.com/TMGTFSRealTimeWebService/tripupdate/tripupdates.pb';
// const VEHICLE_UPDATES_URL = 'https://gtfs-rt.itsmarta.com/TMGTFSRealTimeWebService/vehicle/vehiclepositions.pb'

async function readGTFS() {
    const config = JSON.parse(await readFile(new URL(TRIP_UPDATES_URL), 'utf-8'));
    console.log(config);
    importGtfs(config)
    .then(() => {
        console.log('Import Successful');
    })
    .catch((err) => {
        console.error(err);
    });
}


readGTFS()
```;

Joe-ChenZ avatar Jul 20 '22 18:07 Joe-ChenZ

Try adding

"type": "module"

to your package.json file.

On Wed, Jul 20, 2022 at 11:36 AM Joe-ChenZ @.***> wrote:

C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers>ts-node FutureRouteProvider.tsx C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:851 return old(m, filename); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\node_modules\gtfs\index.js from C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx not supported. Instead change the require of index.js in C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx to a dynamic import() which is available in all CommonJS modules. at Object.require.extensions. [as .js] (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:851:20) at Object. (C:\Users\Joech\GTComputing\Summer 2022 intern\react-rider\providers\FutureRouteProvider.tsx:3:16) at Module.m._compile (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:857:29) at Object.require.extensions. [as .tsx] (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\index.js:859:16) at phase4 (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:466:20) at bootstrap (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:54:12) at main (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:33:12) at Object. (C:\Users\Joech\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:579:5) { code: 'ERR_REQUIRE_ESM' }

I followed the example code and did this, but it generates an error:

import { importGtfs } from 'gtfs';

// import gtfsToGeoJSON from 'gtfs-to-geojson'; import { readFile } from 'fs/promises';

import { util } from "protobufjs"; const TRIP_UPDATES_URL = 'https://gtfs-rt.itsmarta.com/TMGTFSRealTimeWebService/tripupdate/tripupdates.pb'; // const VEHICLE_UPDATES_URL = 'https://gtfs-rt.itsmarta.com/TMGTFSRealTimeWebService/vehicle/vehiclepositions.pb'

async function readGTFS() { const config = JSON.parse(await readFile(new URL(TRIP_UPDATES_URL), 'utf-8')); console.log(config); importGtfs(config) .then(() => { console.log('Import Successful'); }) .catch((err) => { console.error(err); }); }

readGTFS()


—
Reply to this email directly, view it on GitHub
<https://github.com/BlinkTagInc/gtfs-to-geojson/issues/15#issuecomment-1190623545>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXPWJ552MHSI5QAYKMPQTVVBBMHANCNFSM54BZ5CTQ>
.
You are receiving this because you commented.Message ID:
***@***.***>

brendannee avatar Oct 11 '22 09:10 brendannee