No longer resolving file paths correctly - Error: ENOENT: no such file or directory, scandir
See original GitHub issueEnvironment
Knex version: 0.20.9 Database + version: Postgres 10.6 OS: debian
Bug
- Since the latest version of Knex (0.20.9), once knex has switched to the working directory. Knex doesn’t resolve the full path correctly. From the logs, I can see that Knex is trying to resolve the files from, for example,
/app/migrations
when in fact our folder structure is:
/app/config/knexfile.js
/app/config/migrations/*.js
/app/config/seed/*.js
event-service_1 | DB_MIGRATE set to 'true' (default is true)
event-service_1 | Running db migrations...
event-service_1 |
event-service_1 | > event-service@1.0.0 db:migrate /app
event-service_1 | > knex --knexfile ./config/knexfile.js migrate:latest
event-service_1 |
event-service_1 | Working directory changed to /app/config
event-service_1 | Error: ENOENT: no such file or directory, scandir '/app/migrations'
event-service_1 | npm ERR! code ELIFECYCLE
event-service_1 | npm ERR! errno 1
event-service_1 | npm ERR! event-service@1.0.0 db:migrate: `knex --knexfile ./config/knexfile.js migrate:latest`
event-service_1 | npm ERR! Exit status 1
event-service_1 | npm ERR!
event-service_1 | npm ERR! Failed at the event-service@1.0.0 db:migrate script.
event-service_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
event-service_1 |
event-service_1 | npm ERR! A complete log of this run can be found in:
event-service_1 | npm ERR! /home/node/.npm/_logs/2020-02-11T19_29_33_262Z-debug.log
event-service_1 | Completed db migrations
event-service_1 | DB_SEED set to 'true' (default is false)
event-service_1 | Running db seeding...
event-service_1 |
event-service_1 | > event-service@1.0.0 db:seed /app
event-service_1 | > knex --knexfile ./config/knexfile.js seed:run
event-service_1 |
event-service_1 | Working directory changed to /app/config
event-service_1 | Error: ENOENT: no such file or directory, scandir '/app/seeds'
Looks to be related to changes here: https://github.com/knex/knex/commit/947273e24a73545a269fbe90ef30d55889d5db72
Thanks for the help! Richard
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
Error: ENOENT: no such file or directory, scandir
I got the error 'Error: ENOENT: no such file or directory, scandir '**/node_modules/node-sass/vendor', this solution helped me resolve it.
Read more >How To Fix the “Enoent” Error? - Position Is Everything
You can get this error if you use a file path that starts at the directory where scripts are executing but not at...
Read more >ENOENT: no such file or directory when deployed to Vercel
ERROR Error : ENOENT: no such file or directory, scandir '/var/task/data/blog' at Object.readdirSync (fs.js:1043:3) at GetAllPosts ...
Read more >Error: ENOENT: no such file or directory, scandir ... - YouTube
nodejsError: ENOENT : no such file or directory, scandir '**/node_modules/node-sass/vendor' | Module build failed (from .
Read more >express error: enoent: no such file or directory, stat - You.com
I suspect that index.html was not copied to the output directory from where your code resolves the absolute path for res.sendFile(...) .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yup, we look good! Removed the
path.resolve(...)
and that worked. We’ll look at seeing if can’t suggest cleaning that up for all our services too… 😄@rlee89 : Actually, this sorta relates to the earlier conversation between @kibertoad and I.
Generally speaking, it’s risky for modules to make assumptions about the current value of
process.cwd()
. It can lead to all sorts of surprises when another piece of code changes the process’s current working directory.If possible, you should try to resolve paths relative to a fixed value, such as
__dirname
. For example: