BlinkTagInc / node-gtfs

Import GTFS transit data into SQLite and query routes, stops, times, fares and more.
MIT License
437 stars 150 forks source link

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined #169

Closed londonreturns closed 4 days ago

londonreturns commented 5 days ago

I am trying to use gtfs module

` const express = require('express') const app = express() const port = 3000 const gtfs = require('gtfs')

app.get('/', (req, res) => { res.send('Hello World!') })

app.listen(port, () => { console.log(Example app listening on port ${port}) }) `

but i am getting this error

` throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null); ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'gtfsRoutes.js' imported from C:\Users\londonreturns\Downloads\node-backend\server.js at packageResolve (node:internal/modules/esm/resolve:839:9) at moduleResolve (node:internal/modules/esm/resolve:908:18) at defaultResolve (node:internal/modules/esm/resolve:1038:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12) at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38) at ModuleJob._link (node:internal/modules/esm/module_job:126:49) { code: 'ERR_MODULE_NOT_FOUND' } `

image

node version = v22.9.0 npm version = 9.8.0 gtfs version = ^4.14.5"

brendannee commented 5 days ago

Thanks for reporting this issue.

The latest versions of the gtfs module are written as an ESM module, so you can import it like:

import { importGtfs } from 'gtfs';

Here is an example usage

import { importGtfs } from 'gtfs';
import { readFile } from 'fs/promises';
import path from 'node:path';

const config = JSON.parse(
  await readFile(path.join(import.meta.dirname, 'config.json'))
);

try {
  await importGtfs(config);
} catch (error) {
  console.error(error);
}
londonreturns commented 4 days ago

Thank you @brendannee, i was spending way too long on that issue.

brendannee commented 4 days ago

Let me know what you end up creating with this library and if you have any feedback.

londonreturns commented 4 days ago

My plan is to create a realtime public transportation application for Kathmandu (because we don't have one at the moment) using Flutter and NodeJS for my final college project. If I do need help, which I probably will, I will probably end up here multiple times in the next couple of months.