dotenv is a runtime dependency, but is listed as a dev depency in package.json. This causes issues if NODE_ENV=production, under which dependencies are installed, but not devDependencies.
Steps to recreate:
Clone repository
export NODE_ENV=production
npm install
ISSUER={validOktaDomain}/oauth2/default CLIENT_ID={validClientId} CLIENT_SECRET={validClientSecret} npm run okta-hosted-login-server
Expected results:
> @okta/samples-nodejs-express-4@3.1.0 okta-hosted-login-server
> node okta-hosted-login/server.js
(...)
App started on port 8080
Actual results:
> @okta/samples-nodejs-express-4@3.1.0 okta-hosted-login-server
> node okta-hosted-login/server.js
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'dotenv'
Require stack:
- /(...)/samples-nodejs-express-4/config.js
- /(...)/samples-nodejs-express-4/okta-hosted-login/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/derek.tiffany/Documents/GitHub/samples-nodejs-express-4/config.js:2:16)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/(...)/samples-nodejs-express-4/config.js',
'/(...)/samples-nodejs-express-4/okta-hosted-login/server.js'
]
}
Note:
Fix is to simply move dotenv from devDependencies to dependencies in package.json
dotenv
is a runtime dependency, but is listed as a dev depency inpackage.json
. This causes issues ifNODE_ENV=production
, under which dependencies are installed, but not devDependencies.Steps to recreate:
export NODE_ENV=production
npm install
ISSUER={validOktaDomain}/oauth2/default CLIENT_ID={validClientId} CLIENT_SECRET={validClientSecret} npm run okta-hosted-login-server
Expected results:
Actual results:
Note: Fix is to simply move
dotenv
fromdevDependencies
todependencies
inpackage.json