Deploying to Heroku - Error: Cannot find module Providers
When trying to deploy to Heroku, we receive the following runtime error.
{ Error: Cannot find module '/app/providers/Sms/provider'
2018-01-18T00:22:31.325439+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:527:15)
2018-01-18T00:22:31.325441+00:00 app[web.1]: at Function.Module._load (module.js:476:23)
2018-01-18T00:22:31.325442+00:00 app[web.1]: at Module.require (module.js:568:17)
2018-01-18T00:22:31.325443+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-01-18T00:22:31.325445+00:00 app[web.1]: at requireStack (/app/node_modules/require-stack/src/index.js:44:12)
2018-01-18T00:22:31.325446+00:00 app[web.1]: at _.uniq.map (/app/node_modules/@adonisjs/fold/src/Registrar/index.js:104:22)
2018-01-18T00:22:31.325447+00:00 app[web.1]: at arrayMap (/app/node_modules/lodash/lodash.js:660:23)
2018-01-18T00:22:31.325448+00:00 app[web.1]: at Function.map (/app/node_modules/lodash/lodash.js:9571:14)
2018-01-18T00:22:31.325449+00:00 app[web.1]: at interceptor (/app/node_modules/lodash/lodash.js:16970:35)
2018-01-18T00:22:31.325450+00:00 app[web.1]: at thru (/app/node_modules/lodash/lodash.js:8812:14)
2018-01-18T00:22:31.325451+00:00 app[web.1]: at /app/node_modules/lodash/lodash.js:4379:28
2018-01-18T00:22:31.325452+00:00 app[web.1]: at arrayReduce (/app/node_modules/lodash/lodash.js:704:21)
2018-01-18T00:22:31.325453+00:00 app[web.1]: at baseWrapperValue (/app/node_modules/lodash/lodash.js:4378:14)
2018-01-18T00:22:31.325455+00:00 app[web.1]: at LazyWrapper.lazyValue [as value] (/app/node_modules/lodash/lodash.js:1880:16)
2018-01-18T00:22:31.325456+00:00 app[web.1]: at baseWrapperValue (/app/node_modules/lodash/lodash.js:4376:25)
2018-01-18T00:22:31.325460+00:00 app[web.1]: at LodashWrapper.wrapperValue (/app/node_modules/lodash/lodash.js:9067:14) code: 'MODULE_NOT_FOUND' }
2018-01-18T00:22:31.414124+00:00 heroku[web.1]: Process exited with status 0
2018-01-18T00:22:31.428619+00:00 heroku[web.1]: State changed from starting to crashed
Obviously this is because it cannot find the providers folder....
const providers = [
'@adonisjs/framework/providers/AppProvider',
'@adonisjs/auth/providers/AuthProvider',
'@adonisjs/bodyparser/providers/BodyParserProvider',
'@adonisjs/cors/providers/CorsProvider',
'@adonisjs/lucid/providers/LucidProvider',
'@adonisjs/validator/providers/ValidatorProvider',
'adonis-mongoose-model/providers/MongooseProvider',
path.join(__dirname, '..', 'providers', 'Sms/provider'),
path.join(__dirname, '..', 'providers', 'Compass/provider'),
path.join(__dirname, '..', 'providers', 'Cloudinary/provider')
]
Is there a better solutuion to referencing the providers folder than
path.join(__dirname, '..', 'providers', 'xxxx/xxxxx')
?
Managed to find a fix.
const providers = [
'@adonisjs/framework/providers/AppProvider',
'@adonisjs/auth/providers/AuthProvider',
'@adonisjs/bodyparser/providers/BodyParserProvider',
'@adonisjs/cors/providers/CorsProvider',
'@adonisjs/lucid/providers/LucidProvider',
'@adonisjs/validator/providers/ValidatorProvider',
'adonis-mongoose-model/providers/MongooseProvider',
path.join(process.cwd(), 'providers', 'Sms/Provider'),
path.join(process.cwd(), 'providers', 'Compass/Provider'),
path.join(process.cwd(), 'providers', 'Cloudinary/Provider')
]
Suggest replacing
path.join(__dirname, '..', 'providers', 'xxxx/xxxxx')
in docs with
path.join(process.cwd(), 'providers', 'xxxx/xxxxx')
May I know why?
__dirname returns the current directory for a given file.
You should not use process.cwd() because the result change each time we call process.chdir()
console.log(__dirname, process.cwd()); // /Users/md/Documents/projets /Users/md/Documents/projets
process.chdir("/");
console.log(__dirname, process.cwd()); // /Users/md/Documents/projets /
Closing since no answer from issue reporter and seems fine from our side.
The problem is that his provider.js is probably with a capital P (like the docs show as well). Had this problem as well on my raspberry pi
Facing the same issue on Google App Engine. @thetutlage
__dirname returning '/app/start'
Error: Cannot find module '/app/providers/Razorpay/Provider'
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.