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

No knexfile at ... #29

Open
dvisztempacct opened this issue Jul 26, 2018 · 5 comments
Open

No knexfile at ... #29

dvisztempacct opened this issue Jul 26, 2018 · 5 comments

Comments

@dvisztempacct
Copy link

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.

@sheerun
Copy link
Owner

sheerun commented Jul 28, 2018

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

@tataton
Copy link

tataton commented Jul 30, 2018

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!

@sheerun
Copy link
Owner

sheerun commented Jul 30, 2018

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

@dvisztempacct
Copy link
Author

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

@tomasikp
Copy link

+1 for this

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

No branches or pull requests

4 participants