I'm having trouble getting the <Rest API Postgres>...
# help
s
I'm having trouble getting the Rest API Postgres example migrations working. Getting an ES module error
When I click "Migrations" in the console, I get this output in the live lambda client:
Copy code
8ca436e9-8142-4610-a010-ceeec9997a4d REQUEST sgeoghegan-rest-api-postg-ClusterMigrationFunction-3SNcTxJ6VIqU [index.handler] invoked
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/sgeoghegan/dev/rest-api-postgresql/backend/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/sgeoghegan/dev/rest-api-postgresql/backend/migrations/first.js1651861529442.js:1:1
    at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async DynamicFileMigrationProvider.getMigrations (/Users/sgeoghegan/dev/rest-api-postgresql/.sst/artifacts/sgeoghegan-rest-api-postgresql-MyStack-Cluster-MigrationFunction/Users/sgeoghegan/dev/rest-api-postgresql/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:7427:29)
    at async Migrator.resolveMigrations_fn (/Users/sgeoghegan/dev/rest-api-postgresql/.sst/artifacts/sgeoghegan-rest-api-postgresql-MyStack-Cluster-MigrationFunction/Users/sgeoghegan/dev/rest-api-postgresql/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:6223:25)
    at async Migrator.getMigrations (/Users/sgeoghegan/dev/rest-api-postgresql/.sst/artifacts/sgeoghegan-rest-api-postgresql-MyStack-Cluster-MigrationFunction/Users/sgeoghegan/dev/rest-api-postgresql/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:6082:24)
    at async Runtime.handler (/Users/sgeoghegan/dev/rest-api-postgresql/.sst/artifacts/sgeoghegan-rest-api-postgresql-MyStack-Cluster-MigrationFunction/Users/sgeoghegan/dev/rest-api-postgresql/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:7407:12)
removing the
"type": "module"
from /backend/package.json got it working. Just wondering if this is an oversight or not
t
let me look into this, migrations may need to be
.cjs
@Seth Geoghegan the migrations need to be .cjs at the moment, we need to improve our migrator to do a compile step which will solve this