getting error when setting custom path to greenlock #32

Open
opened 2020-02-24 16:00:01 +00:00 by Ghost · 1 comment

Hi,

Since I redeploy my app a lot I have mounted a persistant storage to save my certificates. When I try to set the path using

npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates

I get:

root@localhost:/data/certificates# npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module '/root/.npm/_npx/840/lib/node_modules/greenlock/node_modules/@root/acme/scripts/postinstall'

note the nested node_modules in the path.

I get it when adding any path in the system.

  "devDependencies": {
    "@types/bcrypt": "^3.0.0",
    "@types/bcryptjs": "^2.4.2",
    "@types/connect-flash": "0.0.35",
    "@types/cookie-parser": "^1.4.2",
    "@types/dotenv": "^8.2.0",
    "@types/ejs": "^3.0.0",
    "@types/express": "^4.17.2",
    "@types/express-session": "^1.15.16",
    "@types/hbs": "^4.0.1",
    "@types/lodash": "^4.14.149",
    "@types/lowdb": "^1.0.9",
    "@types/markdown-it": "0.0.9",
    "@types/passport": "^1.0.2",
    "@types/passport-local": "^1.0.33",
    "@types/passport-strategy": "^0.2.35",
    "@types/uuid": "^3.4.6",
    "@types/validator": "^12.0.1",
    "@typescript-eslint/eslint-plugin": "^2.19.0",
    "@typescript-eslint/parser": "^2.19.0",
    "eslint": "^6.8.0",
    "eslint-config-es5": "^0.5.0",
    "husky": "^4.2.1",
    "testcafe": "^1.8.1",
    "ts-node": "^8.6.1",
    "ts-node-dev": "^1.0.0-pre.44",
    "typescript": "^3.7.5",
    "typescript-eslint-parser": "^22.0.0",
    "webpack": "^4.41.5"
  },
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.4",
    "dotenv": "^8.2.0",
    "ejs": "^3.0.1",
    "ejs-lint": "^1.0.1",
    "express": "^4.17.1",
    "express-session": "^1.17.0",
    "flat-file-js": "^2.1.2",
    "greenlock-express": "^4.0.3",
    "lodash": "^4.17.15",
    "lowdb": "^1.0.0",
    "markdown-it": "^10.0.0",
    "passport": "^0.4.1",
    "passport-local": "^1.0.0",
    "uuid": "^3.4.0",
    "validator": "^12.1.0"
  }
}
Hi, Since I redeploy my app a lot I have mounted a persistant storage to save my certificates. When I try to set the path using ``` npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates ``` I get: ``` root@localhost:/data/certificates# npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates internal/modules/cjs/loader.js:983 throw err; ^ Error: Cannot find module '/root/.npm/_npx/840/lib/node_modules/greenlock/node_modules/@root/acme/scripts/postinstall' ``` note the nested `node_modules` in the path. I get it when adding any path in the system. ``` "devDependencies": { "@types/bcrypt": "^3.0.0", "@types/bcryptjs": "^2.4.2", "@types/connect-flash": "0.0.35", "@types/cookie-parser": "^1.4.2", "@types/dotenv": "^8.2.0", "@types/ejs": "^3.0.0", "@types/express": "^4.17.2", "@types/express-session": "^1.15.16", "@types/hbs": "^4.0.1", "@types/lodash": "^4.14.149", "@types/lowdb": "^1.0.9", "@types/markdown-it": "0.0.9", "@types/passport": "^1.0.2", "@types/passport-local": "^1.0.33", "@types/passport-strategy": "^0.2.35", "@types/uuid": "^3.4.6", "@types/validator": "^12.0.1", "@typescript-eslint/eslint-plugin": "^2.19.0", "@typescript-eslint/parser": "^2.19.0", "eslint": "^6.8.0", "eslint-config-es5": "^0.5.0", "husky": "^4.2.1", "testcafe": "^1.8.1", "ts-node": "^8.6.1", "ts-node-dev": "^1.0.0-pre.44", "typescript": "^3.7.5", "typescript-eslint-parser": "^22.0.0", "webpack": "^4.41.5" }, "dependencies": { "bcryptjs": "^2.4.3", "connect-flash": "^0.1.1", "cookie-parser": "^1.4.4", "dotenv": "^8.2.0", "ejs": "^3.0.1", "ejs-lint": "^1.0.1", "express": "^4.17.1", "express-session": "^1.17.0", "flat-file-js": "^2.1.2", "greenlock-express": "^4.0.3", "lodash": "^4.17.15", "lowdb": "^1.0.0", "markdown-it": "^10.0.0", "passport": "^0.4.1", "passport-local": "^1.0.0", "uuid": "^3.4.0", "validator": "^12.1.0" } } ```
Author

seems like the error was casused by running npx from outside my app root directory.

Once I ran it from the app dir I've only got an unhandled promise rejection:


root@localhost:/academy# npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates
(node:1393) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.Rc._initSync (/academy/node_modules/@root/greenlock/lib/rc.js:19:19)
    at Object.Init._init (/academy/node_modules/@root/greenlock/lib/init.js:116:17)
    at Object.greenlock._create (/academy/node_modules/@root/greenlock/greenlock.js:58:22)
    at Object.G.create (/academy/node_modules/@root/greenlock/greenlock.js:482:15)
    at Object.Flags.init (/academy/node_modules/@root/greenlock/bin/lib/flags.js:184:31)
    at Object.<anonymous> (/academy/node_modules/@root/greenlock/bin/defaults.js:11:7)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
(node:1393) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:1393) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

however the app will not run:

> NODE_ENV=production node ./build/index.js

Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
/academy/node_modules/@root/greenlock/lib/rc.js:22
            throw e;
            ^

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.Rc._initSync (/academy/node_modules/@root/greenlock/lib/rc.js:19:19)
    at Object.Init._init (/academy/node_modules/@root/greenlock/lib/init.js:116:17)
    at Object.greenlock._create (/academy/node_modules/@root/greenlock/greenlock.js:58:22)
    at Object.G.create (/academy/node_modules/@root/greenlock/greenlock.js:482:15)
    at Object.module.exports.create (/academy/node_modules/@root/greenlock-express/greenlock-shim.js:22:31)
    at Object.Single.create (/academy/node_modules/@root/greenlock-express/single.js:9:52)
    at Object.GLE.init (/academy/node_modules/@root/greenlock-express/greenlock-express.js:47:35)
    at Object.<anonymous> (/academy/build/index.js:64:10)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)

my server looks like this:


  require('greenlock-express')
    .init({
      packageRoot: './',
      configDir: process.env.CERTIFICATES_PATH,
      maintainerEmail: '<my email>@gmail.com',
      cluster: false
    })
    .serve(app);

process.env.CERTIFICATES_PATH=/data/certificates

inside /data/certificates I have the files generated previously by greenlock:

accounts  config.json  config.json.bak  live

config.json is

{
  "defaults": {
    "store": {
      "basePath": "/data/certificates",
      "module": "greenlock-store-fs"
    },
    "challenges": {
      "http-01": {
        "module": "acme-http-01-standalone"
      }
    },
    "renewOffset": "-45d",
    "renewStagger": "3d",
    "accountKeyType": "EC-P256",
    "serverKeyType": "RSA-2048",
    "subscriberEmail": "<my email>@gmail.com"
  },
  "sites": [
    {
      "subject": "li2048-115.members.linode.com",
      "altnames": [
        "li2048-115.members.linode.com"
      ],
      "renewAt": 1586364310540
    }
  ]
}

the server is a nanolinode I'm certyfing it's dev address but I do plan to move to a proper domain once it works.

As you can see I have made it work once before. However once I rebuild my linde and tried to follow the same steps again it fell apart.

os: debian 10

npm -v: 6.13.7 and 6.13.4

node -v: 13.9.0 and 12.16.1

seems like the error was casused by running npx from outside my app root directory. Once I ran it from the app dir I've only got an unhandled promise rejection: ``` root@localhost:/academy# npx greenlock defaults --store greenlock-store-fs --store-base-path /data/certificates (node:1393) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at Object.Rc._initSync (/academy/node_modules/@root/greenlock/lib/rc.js:19:19) at Object.Init._init (/academy/node_modules/@root/greenlock/lib/init.js:116:17) at Object.greenlock._create (/academy/node_modules/@root/greenlock/greenlock.js:58:22) at Object.G.create (/academy/node_modules/@root/greenlock/greenlock.js:482:15) at Object.Flags.init (/academy/node_modules/@root/greenlock/bin/lib/flags.js:184:31) at Object.<anonymous> (/academy/node_modules/@root/greenlock/bin/defaults.js:11:7) at Module._compile (internal/modules/cjs/loader.js:1151:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10) at Module.load (internal/modules/cjs/loader.js:1000:32) (node:1393) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:1393) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ``` however the app will not run: ``` > NODE_ENV=production node ./build/index.js Warning: connect.session() MemoryStore is not designed for a production environment, as it will leak memory, and will not scale past a single process. /academy/node_modules/@root/greenlock/lib/rc.js:22 throw e; ^ SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at Object.Rc._initSync (/academy/node_modules/@root/greenlock/lib/rc.js:19:19) at Object.Init._init (/academy/node_modules/@root/greenlock/lib/init.js:116:17) at Object.greenlock._create (/academy/node_modules/@root/greenlock/greenlock.js:58:22) at Object.G.create (/academy/node_modules/@root/greenlock/greenlock.js:482:15) at Object.module.exports.create (/academy/node_modules/@root/greenlock-express/greenlock-shim.js:22:31) at Object.Single.create (/academy/node_modules/@root/greenlock-express/single.js:9:52) at Object.GLE.init (/academy/node_modules/@root/greenlock-express/greenlock-express.js:47:35) at Object.<anonymous> (/academy/build/index.js:64:10) at Module._compile (internal/modules/cjs/loader.js:1151:30) ``` my server looks like this: ``` require('greenlock-express') .init({ packageRoot: './', configDir: process.env.CERTIFICATES_PATH, maintainerEmail: '<my email>@gmail.com', cluster: false }) .serve(app); ``` process.env.CERTIFICATES_PATH=/data/certificates inside `/data/certificates` I have the files generated previously by greenlock: ``` accounts config.json config.json.bak live ``` config.json is ``` { "defaults": { "store": { "basePath": "/data/certificates", "module": "greenlock-store-fs" }, "challenges": { "http-01": { "module": "acme-http-01-standalone" } }, "renewOffset": "-45d", "renewStagger": "3d", "accountKeyType": "EC-P256", "serverKeyType": "RSA-2048", "subscriberEmail": "<my email>@gmail.com" }, "sites": [ { "subject": "li2048-115.members.linode.com", "altnames": [ "li2048-115.members.linode.com" ], "renewAt": 1586364310540 } ] } ``` the server is a nanolinode I'm certyfing it's dev address but I do plan to move to a proper domain once it works. As you can see I have made it work once before. However once I rebuild my linde and tried to follow the same steps again it fell apart. os: debian 10 npm -v: 6.13.7 and 6.13.4 node -v: 13.9.0 and 12.16.1
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: root/greenlock-express.js#32
No description provided.