KristjanESPERANTO / MMM-PublicTransportHafas

This is a module for MagicMirror² to display public transport departures.
MIT License
21 stars 6 forks source link

error when running npm query #165

Closed b1nary-b0b closed 7 months ago

b1nary-b0b commented 8 months ago

Bug description error when running npm query

Module config freshly pulled from github.

Screenshots `root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas# npm run query

mmm-publictransporthafas@2.1.1 query node ./convenience/query_stations.mjs

file:///var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas/convenience/query_stations.mjs:122 const {profile} = await import(hafas-client/p/${profileName}/index.js); ^^^^^

SyntaxError: Unexpected reserved word at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18) at async link (internal/modules/esm/module_job.js:42:21) root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas# npm run query Berlin

mmm-publictransporthafas@2.1.1 query node ./convenience/query_stations.mjs "Berlin"

file:///var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas/convenience/query_stations.mjs:122 const {profile} = await import(hafas-client/p/${profileName}/index.js); ^^^^^

SyntaxError: Unexpected reserved word at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18) at async link (internal/modules/esm/module_job.js:42:21) root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas# `

Additional context I installed the Module and run the command npm query which caused the above error. I also tried to supply the command with a city name, but also no success - same error.

Can you please advise? Much appreciated <3

b1nary-b0b commented 8 months ago

I also tried to supply it with "db" and "sbb", but still does not work.

root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas# npm run query db

mmm-publictransporthafas@2.1.1 query node ./convenience/query_stations.mjs "db"

internal/modules/cjs/loader.js:818 throw err; ^

Error: Cannot find module '/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas/convenience/query_stations.mjs' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.Module._load (internal/modules/cjs/loader.js:667:27) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas# npm run query sbb

mmm-publictransporthafas@2.1.1 query node ./convenience/query_stations.mjs "sbb"

internal/modules/cjs/loader.js:818 throw err; ^

Error: Cannot find module '/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas/convenience/query_stations.mjs' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.Module._load (internal/modules/cjs/loader.js:667:27) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas#

I also checked the script is present: root@server:/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas/convenience# ls query_stations.mjs

KristjanESPERANTO commented 8 months ago

That's odd. I just did a clean install of the module and can't reproduce this issue.

Which node version do you have?

Run node -v to check.

Did you run npm ci oder npm install in the modules directory?

I just noticed that the path "/var/lib/docker/volumes/magicmirror_modules/_data/MMM-PublicTransportHafas" is a bit strange. I never used MagicMirror in a docker container. Is that the right place to install modules when you use docker?

b1nary-b0b commented 7 months ago

Hey, I ran node -v and the version is 12.22.9. I also installed it via npm ci as advised by you here: https://github.com/KristjanESPERANTO/MMM-PublicTransportHafas/issues/161#issuecomment-2028498507

yeah it is the right place, other modules like MMM-CalendarExt3 work fine.

Thanks for your help!

KristjanESPERANTO commented 7 months ago

Nice, that it worked 🙂 But node 12 is very old. The current version of MagicMirror doesn't work with such an old version. I recommend to install node 20.

b1nary-b0b commented 7 months ago

Hey, i updated node and now it works, thanks!

One more thing: the documentation says I need to provide my satation ID in this format "XXXXXXX". The query for my station only returns a 6 digit number. But supplying only the 6 digit number did not work - nothing was shown in the plugin. I checked your example config and there it shows 2 leading 0s - "008012202". I tried to append 2 leading zeros and it worked fine. So maybe you can update the table with configuration values with information, that the number needs 2 leadings zeros in order to work.

Thanks for creating this plugin and for your great help! Much appreciated! :)

KristjanESPERANTO commented 7 months ago

That's odd. Both "008012202" and "8012202" are working. Which station ID do you use?