ether/ep_comments_page

Trying to install ep_comments_page from source, failing to load hook functions

riedelcastro opened this issue · 3 comments

I am trying to install the ep_comments_page from source. To this end, I cloned the repo locally to /some/folder/ep_comments_page and then tried to install the plugin via npm install --no-save --legacy-peer-deps /some/folder/ep_comments_page/ep_comments_page.

Something happens, but when I run src/bin/run.sh I get a lot of errors of the type I copied below. Obviously I am doing something wrong, but I am not quite sure how to fix it. Could anyone help?

[2022-04-01 22:51:22.669] [ERROR] console - Failed to load hook function "/Users/sriedel/projects/etherpad-lite/node_modules/ep_comments_page/index:padInitToolbar" for plugin "ep_comments_page" part "comments_page" hook set "hooks" hook "padInitToolbar": Error: Cannot find module 'ep_etherpad-lite/static/js/AttributePool'
Require stack:
- /Users/sriedel/projects/ep_comments_page/index.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/shared.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/plugins.js
- /Users/sriedel/projects/etherpad-lite/src/node/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sriedel/projects/ep_comments_page/index.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
[2022-04-01 22:51:22.670] [ERROR] console - Failed to load hook function "/Users/sriedel/projects/etherpad-lite/node_modules/ep_comments_page/index:padRemove" for plugin "ep_comments_page" part "comments_page" hook set "hooks" hook "padRemove": Error: Cannot find module 'ep_etherpad-lite/static/js/AttributePool'
Require stack:
- /Users/sriedel/projects/ep_comments_page/index.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/shared.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/plugins.js
- /Users/sriedel/projects/etherpad-lite/src/node/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sriedel/projects/ep_comments_page/index.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
[2022-04-01 22:51:22.671] [ERROR] console - Failed to load hook function "/Users/sriedel/projects/etherpad-lite/node_modules/ep_comments_page/index:padCopy" for plugin "ep_comments_page" part "comments_page" hook set "hooks" hook "padCopy": Error: Cannot find module 'ep_etherpad-lite/static/js/AttributePool'
Require stack:
- /Users/sriedel/projects/ep_comments_page/index.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/shared.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/plugins.js
- /Users/sriedel/projects/etherpad-lite/src/node/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sriedel/projects/ep_comments_page/index.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
[2022-04-01 22:51:22.673] [ERROR] console - Failed to load hook function "/Users/sriedel/projects/etherpad-lite/node_modules/ep_comments_page/index:socketio" for plugin "ep_comments_page" part "comments_page" hook set "hooks" hook "socketio": Error: Cannot find module 'ep_etherpad-lite/static/js/AttributePool'
Require stack:
- /Users/sriedel/projects/ep_comments_page/index.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/shared.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/plugins.js
- /Users/sriedel/projects/etherpad-lite/src/node/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sriedel/projects/ep_comments_page/index.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
[2022-04-01 22:51:22.673] [ERROR] console - Failed to load hook function "/Users/sriedel/projects/etherpad-lite/node_modules/ep_comments_page/index:expressCreateServer" for plugin "ep_comments_page" part "comments_page" hook set "hooks" hook "expressCreateServer": Error: Cannot find module 'ep_etherpad-lite/static/js/AttributePool'
Require stack:
- /Users/sriedel/projects/ep_comments_page/index.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/shared.js
- /Users/sriedel/projects/etherpad-lite/src/static/js/pluginfw/plugins.js
- /Users/sriedel/projects/etherpad-lite/src/node/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sriedel/projects/ep_comments_page/index.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

I found one way to fix this: move the ep_comments_page folder into the top level etherpad-lite folder, and then install from there. Is there a way to avoid this? Maybe install while being in parent of ep_comments_page and then specify where to install the modules to?

Ah no, actually that still didn't work, I was accidentally still NOT installing it from source, that's why it looked like it worked. So I still have the problems in the original post.

The issue is that ep_comments_page needs to access stuff from Etherpad core, so Node.js needs to be able to find Etherpad core from ep_comments_page. Thus, you need two symlinks: one from Etherpad core to the plugin, and one from the plugin back to Etherpad core:

cd /path/to/etherpad-lite/node_modules && ln -s /path/to/ep_comments_page
cd /path/to/ep_comments_page/node_modules && ln -s /path/to/etherpad-lite/src ./ep_etherpad-lite

Instead of manually creating the symlinks you can use npm link to create the symlinks for you:

# One-time setup (you might want to customize `prefix` in your `~/.npmrc` first):
cd /path/to/etherpad-lite/src && npm link
cd /path/to/ep_comments_page && npm link
# Create the symlinks:
cd /path/to/etherpad-lite && npm link ep_comments_page
cd /path/to/ep_comments_page && npm link ep_etherpad-lite

You'll have to recreate the symlinks whenever you run npm install because npm thinks they're unused and "helpfully" cleans them up.

As an alternative, you can clone the ep_comments_page repo inside Etherpad's node_modules folder (no symlinks required):

cd /path/to/etherpad-lite/node_modules
git clone https://github.com/ether/ep_comments_page.git