2

I am aware of the other questions about this issue. The answers on them are of no help, however. I've been dealing with Node and npm for a few years and I've never come across something so confusing. This is my first time dealing with socket.io, however.

I've installed socket.io as a dependency on a git submodule of my project:

npm install --save socket.io

Then I require it:

const io = require("socket.io")(8099);

However, when I attempt to run the app, I get an error:

[error:app 10:31:32.339 C:\Users\<username>\dev\projects\js-ps-app\generator\generator-core\app.js:336:37] Unable to load plugin at 'C:\Users\<username>\dev\projects\js-ps-app\generator\plugins\generator-starter': Could not load plugin at path 'C:\Users\<username>\dev\projects\js-ps-app\generator\plugins\generator-starter': Cannot find module 'socket.io'

When attempting to reference the module relatively:

const io = require(".\\node_modules\\socket.io")(8099);

The error seems to shift to engine.io, which isn't even referenced in my project:

[error:app 10:38:40.630 C:\Users\<username>\dev\projects\js-ps-app\generator\generator-core\app.js:336:37] Unable to load plugin at 'C:\Users\<username>\dev\projects\js-ps-app\generator\plugins\generator-starter': Could not load plugin at path 'C:\Users\<username>\dev\projects\js-ps-app\generator\plugins\generator-starter': Cannot find module 'engine.io'

I am at a loss to know what to do.

For context: This is in the middle of working on Davide Barranca's Native Photoshop Apps video course—Lesson #15, specifically. Adobe Generator is working and connecting to Adobe Photoshop just fine. You can see where this project stands currently at its repo.

For example, here's the main repo's package.json:

{
  "name": "js-ps-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "nwdev": "concurrently --kill-others --raw \"npm:serve\" \".\\node_modules\\.bin\\run .\\nwdev\" --success 'first'",
    "generator": "node --inspect .\\generator\\generator-core\\app -f .\\generator\\plugins -v"
  },
  "dependencies": {
    "@mdi/font": "^3.6.95",
    "core-js": "^3.6.5",
    "roboto-fontface": "*",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "vue-the-mask": "^0.11.1",
    "vuetify": "^2.2.11",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "7zip-bin-win": "^2.2.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-eslint": "^10.1.0",
    "concurrently": "^5.3.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.1.0",
    "node-sass": "^4.12.0",
    "nw-vue-devtools-prebuilt": "0.0.10",
    "nwjs-builder-phoenix": "^1.15.0",
    "sass": "^1.19.0",
    "sass-loader": "^8.0.2",
    "vue-cli-plugin-vuetify": "~2.0.7",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.3.0"
  }
}

And here's generator-starter's package.json, which is what needs socket.io:

{
  "name": "generator-starter",
  "version": "1.0.0",
  "description": "Blank Adobe Generator Plugin",
  "main": "main.js",
  "generator-core-version": "~3",
  "menu": {
    "id": "generator-starter",
    "label": "Generator Plugin"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Davide Barranca",
  "license": "ISC",
  "dependencies": {
    "engine.io": "^4.0.1",
    "socket.io": "^2.3.0"
  }
}

"Running the app" means running npm run generator from the root of the project. It uses node to run app.js inside generator\generator-core, which takes the sibling directory generator\plugins as an argument.

3
  • FYI, engine.io is a sub-component of socket.io (a module that socket.io uses internally). This sounds like socket.io is perhaps not installed in the right place - something which may be unique because of the plug-in architecture you're using.
    – jfriend00
    Commented Nov 3, 2020 at 16:53
  • did you first npm init and then installed it?
    – Ilijanovic
    Commented Nov 3, 2020 at 17:18
  • @jfriend00: It's installed in generator\plugins\generator-starter`, which is specifically where I was instructed to install it in the course. @lfaruki: No need; a package.json` was already included when I cloned the generator-starter repo as a submodule.
    – Sturm
    Commented Nov 3, 2020 at 17:47

1 Answer 1

2
+100

Disclaimer: It's impossible for me to reproduce your error given that a) I'm on Mac, b) I don't have Photoshop and c) I didn't watch the video tutorial. Still, if you bare with me, I'm pretty sure the following will hint you in the proper direction.

The error you are getting is not actually related to socket.io or engine.io. Any dependency that you would declare from your plugin (and that it is not already a dependency of the generator) would trigger the same issue.

The problem is essentially that your plugin's node_modules directory is not actually used for dependency resolution. I'd expect that you can confirm this by adding something like console.log(require.paths) at the top of your plugin's source file.

Then why is it not used? Because generator hijack modules resolutions to disallow loading dependencies from outside of your plugin's node_modules (see Generator's main file: app.js). Note that this is a recent change (July 15, 2020) which explains why the setup you use may work in the tutorial but no longer works.

Now, I'm not sure exactly what's wrong with generator's patched module resolution. Apparently, it doesn't support symlinked plugins directories, but then again, I don't think this is your case. Could it be that some of your dependency may have been hoisted to a parent node_module directory? Another thing is that the construction of safe paths seems to include the "plugins" folder itself (rather than the directory of a specific plugin)... Could be a problem.

Anyway, at this point, I suggest that you 1) try downgrading generator-core's source to tag 3.12.0, 2) if it works, open a ticket on generator-core's bug tracker, then 3) revert generator-core to currently version (this is a security fix, so you should not ignore it) and try to work out a solution.

1
  • Thank you, jwatkins. Yes, you are correct in that the problem lies in that recent change with node_modules. My plugin directories are not symlinked, so something else seems to be wrong with their restriction that it isn't reading modules from the plugin directory. The downgrade to 3.12.0 alleviates the issue and I'll have to stick with it for development for now. I'll definitely open a ticket about this, though, thank you.
    – Sturm
    Commented Nov 10, 2020 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.