Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jamesvillarrubia opened this issue Feb 29, 2024 · 1 comment · Fixed by #3444
Closed

Comments

@jamesvillarrubia
Copy link
Contributor

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
Copy link
Member

daffl commented Feb 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants