You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose adding '.cjs' to the list of extensions to support using Knex in Node projects with "type": "module" enabled while running Knex in CommonJS mode.
The text was updated successfully, but these errors were encountered:
Environment
Knex version: 0.21.17
Database + version: postgres (PostgreSQL) 11.5
OS: MacOS Big Sur 11.2.3
NodeJS: v14.15.1
Bug
I am running NodeJS with ES modules enabled ("type": "module") and with Knex running with .cjs extension:
knexfile.cjs
knex.cjs
Migration files and seed file also have .cjs extension:
migrations
↳ articleTable.cjs
↳ userTable.cjs
seeds
↳ articleTable.cjs
I can run migrations like this:
npx knex migrate:latest --knexfile knexfile.cjs
This works normally.
Error
But when I run the seed like this:
npx knex seed:run --knexfile knexfile.cjs
I receive error "No seed files exist"
Solution
I discovered the problem, which is in the Seeder.js file's setConfig(config) {} function:
If I add '.cjs' to the loadExtensions array, my seed file runs normally:
Proposal
I propose adding '.cjs' to the list of extensions to support using Knex in Node projects with "type": "module" enabled while running Knex in CommonJS mode.
The text was updated successfully, but these errors were encountered: