stackernews / stacker.news

Internet communities that pay you Bitcoin
https://stacker.news
MIT License
430 stars 109 forks source link

Production build can't find module `lightning` #1547

Open huumn opened 15 hours ago

huumn commented 15 hours ago

I suspect this is caused by #1521 given lib/lnd.js didn't exist before then.

This is going to be tricky to reproduce in dev, but it'll require getting an npm run build going then attempting to run it.

Nov  6 01:57:31 ip-172-31-81-59 web: ⨯ Error: Cannot find module 'lightning'
Nov  6 01:57:31 ip-172-31-81-59 web: Require stack:
Nov  6 01:57:31 ip-172-31-81-59 web: - /var/app/staging/lib/lnd.js
Nov  6 01:57:31 ip-172-31-81-59 web: at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
Nov  6 01:57:31 ip-172-31-81-59 web: at /var/app/current/node_modules/next/dist/server/require-hook.js:55:36
Nov  6 01:57:31 ip-172-31-81-59 web: at Function.resolve (node:internal/modules/helpers:188:19)
Nov  6 01:57:31 ip-172-31-81-59 web: at c (/var/app/current/.next/server/chunks/4926.js:3935:447)
Nov  6 01:57:31 ip-172-31-81-59 web: at /var/app/current/.next/server/chunks/4926.js:1936:2990 {
Nov  6 01:57:31 ip-172-31-81-59 web: code: 'MODULE_NOT_FOUND',
Nov  6 01:57:31 ip-172-31-81-59 web: requireStack: [ '/var/app/staging/lib/lnd.js' ]
Nov  6 01:57:31 ip-172-31-81-59 web: }
ekzyis commented 15 hours ago

Wild guess, but maybe it's related to relative paths which are different in the production build?

huumn commented 14 hours ago

That would make sense. I just don't know where the relative path is coming from.

riccardobl commented 10 hours ago

This is due to the way the code gets the absolute path of the protobuf files

  const lightningModulePath = req.resolve('lightning')
  const pathForProto = proto => join(lightningModulePath, protosDir, proto)

likely webpacks does some module mangling in production to remove unused code and somehow we end up without this module that is needed at runtime.

~~Imo we need to revert back to the privoxy workaround or fully fork the ln-service and lightning repos. The latter is very hard to do in a maintenable way, because the original repos don't even tag releases...~~

riccardobl commented 9 hours ago

I've come up with a workaround https://github.com/stackernews/stacker.news/pull/1548 , but i can't test it fully in the dev environment.