knex-migrate icon indicating copy to clipboard operation
knex-migrate copied to clipboard

No knexfile at ...

Open dvisztempacct opened this issue 7 years ago • 5 comments

The "No knexfile at" error message is confusing when the actual problem is a "Cannot find module" error occurring deeper in the recursive module resolution of your knexfile.js.

For example, create a knexfile.js and add to it require("module-that-does-not-exist")

knex-migrate will tell you that you:

No knex file at /path/to/your/project/knexfile.js

Which isn't exactly true.

dvisztempacct avatar Jul 26 '18 20:07 dvisztempacct

The knexfile is supposed to be exactly at /path/to/your/project/knexfile.js. Sorry if code suggests otherwise, but the message is correct.

sheerun avatar Jul 28 '18 09:07 sheerun

I think this isn't what the original commenter meant. If knex-migrate fails to resolve an import within knexfile.js, it reports:

No knexfile at *dirname*; Please create one or bootstrap using 'knex init'

It does this even though knexfile.js exists and is located correctly. So, for example, for:

_knexfile.js_

const config = require('config');
module.exports = {
  client: 'pg',
  connection: { user: config.get('DB_USER'), database: config.get('DB_NAME') }
};

If I've failed to install config, I get the "No knexfile" error. I understand this is a simplistic example (isn't failing to install config my fault after all?), but if your knexfile.js contains some logic that templates the export object from different sources/imports, you could imagine a trace being useful for debugging here.

It looks like this is a consequence of a regex test in src/index.js that reports all "cannot find module" errors as being due to a missing knexfile. Could this test be made more narrow, so that more errors break thru to throw err?

Thx, helpful package!

tataton avatar Jul 30 '18 01:07 tataton

Yes, I understand it now. This needs to be fixed

sheerun avatar Jul 30 '18 09:07 sheerun

@tataton thanks for the clarification. My original post was a little confusing...

dvisztempacct avatar Oct 03 '18 20:10 dvisztempacct

+1 for this

tomasikp avatar Jul 11 '20 06:07 tomasikp