Hi, I've noticed for migrations that seed seems to...
# seed
Hi, I've noticed for migrations that seed seems to want commonjs format? i.e. I'm running into this issue whilst deploying:
Copy code
❌ dev-medii-DatabaseStack: Received response status [FAILED] from custom resource. Message returned: Unexpected token 'export'

Logs: /aws/lambda/dev-medii-DatabaseStack-ClusterMigrationFunctionC4-Dqwx591T1sGb

export const up = async (db) => {

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:192:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async FileMigrationProvider.getMigrations (/var/task/tmp/seed/source/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:6772:27)
    at async Migrator.resolveMigrations_fn (/var/task/tmp/seed/source/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:6228:25) (RequestId: 3c501ccb-3f77-4c45-b55d-2b029c43ef44)
06:28:37 | UPDATE_IN_PROGRESS                           | AWS::CloudFormation::Stack | dev-medii-DatabaseStack
My local copy doesn't like commonjs, and if I convert them to .cjs files then the local SST console doesn't recognize them, is there some way I can tell seed to use ES modules instead of cjs? my package.json and tsconfig.json are already set to module
Hey @Scott, the error actually comes from the actual Lambda function running the migration.
Can you try using
instead of
like this example? https://docs.serverless-stack.com/constructs/RDS#migrations-with-postgresql
@Frank, Yeah I believe that would work for seed, the problem is my setup expects esm instead of commonjs. So then it breaks locally - 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 'D:\Work\medii\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. and I can't use .cjs files as then the migration files aren't picked up by SST
You just need to make the migrations files this way. With
file extension.
I believe that's what I have, but because my package.json has "type": "module" it breaks: e.g. see attached image
@Frank, I see you added a checkmark, to have the solution mentioned above I would need to use commonjs for the entire backend? Is that the prescribed solution?
@Frank any updates on this?