smogon / pokemon-showdown

Pokémon battle simulator.
https://pokemonshowdown.com
MIT License
4.8k stars 2.8k forks source link

`tools/team-generation-benchmark.js` fails because of `require` path #10644

Open larry-the-table-guy opened 2 weeks ago

larry-the-table-guy commented 2 weeks ago

Running node ./tools/team-generation-benchmark.js random gives me this error

$ node ./tools/team-generation-benchmark.js random
node:internal/modules/cjs/loader:1143
  throw err;
  ^

Error: Cannot find module '../sim'
Require stack:
- /redacted/tools/team-generation-benchmark.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/redacted/tools/team-generation-benchmark.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/redacted/tools/team-generation-benchmark.js'
  ]
}

Node.js v18.20.4

I think these lines got left behind during a previous build system migration. https://github.com/smogon/pokemon-showdown/blob/269e6f3751289e5526f6a3a09dfc652c55a7d217/tools/team-generation-benchmark.js#L3-L4

It works when I add dist/ to the path, but that doesn't seem to trigger a rebuild if the TS files change. I'm pretty clueless when it comes to compiling JS/TS so I don't know what the best fix is.

asingh04 commented 1 day ago

I could be wrong, but importing or requireing a TS file in a JS file will not work at all. Building the dist/ folder is probably the right way.

In order to automatically build when changes happen in the TS file, we can probably add a watcher like nodemon