I'm having difficulties running an express app in docker with node 10.9.0 because of an import:
root@e85495ae1c9e:/usr/app/backend# node app.js
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '/usr/app/backend/models/todo'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/usr/app/backend/app.js:7:12)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
Code works locally, but not in docker.
File reported missing is definitely there:
root@e85495ae1c9e:/usr/app/backend/models# ls -alsh
total 12K
4.0K drwxr-xr-x 2 root root 4.0K Aug 22 12:56 .
4.0K drwxr-xr-x 1 root root 4.0K Aug 24 14:48 ..
4.0K -rwxr-xr-x 1 root root 211 Aug 22 12:57 Todo.js
The import inside app.js
causing trouble is this (note that I'm addressing this via dirname because I had zero luck with relative import either):
var Todo = require(path.join((__dirname), "/models/todo"));
I couldn't find anyone with a similar error while searching the web, so I'm posting this here hoping for a little help.
Let me know if more information is needed.
Also if you're downvoting this, kindly comment as to why, so I'll know where I messed up.
Just wanted to add this as an answer for future readers.
The issue was with casing. He was requiring todo when the file was Todo. Always make sure to require the correct casing. You cannot rely on the OS to find the right file.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments