okta / samples-nodejs-express-4

Express 4 samples. Will publish an artifact that can be consumed by end-to-end sample repos
Other
120 stars 121 forks source link

Exception when NODE_ENV=production due to dotenv being a runtime dependency but listed as devDependency #114

Closed derektiffany closed 3 years ago

derektiffany commented 3 years ago

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:

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

derektiffany commented 3 years ago

PR #115 submitted which would resolve this issue.

oleksandrpravosudko-okta commented 3 years ago

Merged in https://github.com/okta/samples-nodejs-express-4/commit/64afdc6dc2e1d3f1595ab22ee7c1e08e133e97a9