feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Knex migration:make format not compatible with Feathers ES module settings #3435

Closed jamesvillarrubia closed 3 months ago

jamesvillarrubia commented 4 months ago

Steps to reproduce

  1. Fresh install of feathers via cli. (JS, postgres, typebox, etc.)
  2. Create migration via npm run migrate:make
  3. Run migration npm run migrate

Expected behavior

Template for knex migration should match the ES modules style generated by the CLI.

Actual behavior

Error is thrown:

exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '.../api/protoFJ/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '.../api/protoFJ/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file://.../api/protoFJ/migrations/20240229202710_users.js:5:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
    at async .../api/protoFJ/node_modules/knex/lib/migrations/migrate/Migrator.js:86:15
    at async Promise.all (index 0)
    at async Migrator.latest (.../api/protoFJ/node_modules/knex/lib/migrations/migrate/Migrator.js:83:9)
    at async Command.<anonymous> (.../api/protoFJ/node_modules/knex/bin/cli.js:250:32)

Current template output with knex

exports.up = function(knex) {};

Should likely be

export async function up(knex) {}

System configuration

Module versions Feathers: 5.0.23 Knex: 3.1.0

NodeJS version: v20

Operating System: OSX

daffl commented 4 months ago

You can change the output for knex migrate:make with the -x command (knex migrate:make -x mjs in this case)