mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +02:00
The derived-signals seed bundle failed on Railway with:
[Regional-Snapshots] Error [ERR_MODULE_NOT_FOUND]: Cannot find module
'/shared/geography.js' imported from /app/seed-regional-snapshots.mjs
Root cause: the Railway cron service for derived-signals deploys with
rootDirectory=scripts, so scripts/ becomes the container /app root. The
repo-root shared/ folder is NOT copied into the container.
seed-regional-snapshots.mjs imported '../shared/geography.js' which
resolved to /shared/geography.js at runtime and blew up. Same for four
scripts/regional-snapshot/* compute modules using '../../shared/...'.
Fix: mirror the runtime shared assets into scripts/shared/ and update
the five import paths.
- Add scripts/shared/geography.js (byte-for-byte copy of shared/geography.js)
- Add scripts/shared/package.json with {"type": "module"} so Node
parses geography.js as ESM inside the rootDirectory=scripts deploy.
scripts/package.json does NOT set type:module.
- scripts/shared/iso2-to-region.json and iso3-to-iso2.json were already
mirrored from prior PRs, no change needed.
- scripts/seed-regional-snapshots.mjs:
'../shared/geography.js' -> './shared/geography.js'
- scripts/regional-snapshot/actor-scoring.mjs:
scripts/regional-snapshot/evidence-collector.mjs:
scripts/regional-snapshot/scenario-builder.mjs:
'../../shared/geography.js' -> '../shared/geography.js'
- scripts/regional-snapshot/balance-vector.mjs:
'../../shared/geography.js' -> '../shared/geography.js'
'../../shared/iso3-to-iso2.json' -> '../shared/iso3-to-iso2.json'
JSDoc type imports like {import('../../shared/regions.types.js').X}
are intentionally NOT changed. They live inside /** */ comments,
Node ignores them at runtime, and tsc still resolves them correctly
from the repo root during local typecheck.
Regression coverage: new tests/scripts-shared-mirror.test.mjs
1. Asserts scripts/shared/{geography.js, iso2-to-region.json,
iso3-to-iso2.json, un-to-iso2.json} are byte-for-byte identical
to their shared/ canonical counterparts.
2. Asserts scripts/shared/package.json has type:module.
3. For each regional-snapshot seed file, resolves every runtime
"import ... from ...shared/..." to an absolute path and asserts
it lands inside scripts/shared/. A regression that reintroduces
"../shared/" from a scripts/ file or "../../shared/" from a
scripts/regional-snapshot/ file will fail this check.
Verified with a temp-dir simulation of rootDirectory=scripts: all
five modules load clean. Full npm run test:data suite passes 4298/4298.
Secondary observation (not in this PR): the same log shows
Cross-Source-Signals missing 4 upstream keys (supply_chain:shipping:v2,
gdelt:intel:tone:{military,nuclear,maritime}), producing 0 composite
escalation zones. That is an upstream data-freshness issue in the
supply-chain and gdelt-intel seeders, not in this bundle.
4 lines
23 B
JSON
4 lines
23 B
JSON
{
|
|
"type": "module"
|
|
}
|