Skip to content

Node modules not loading from plugin dir #423

@SturmB

Description

@SturmB

I have learned that a recent change caused generator-core to only load modules from its own directory or from the plugins in its sibling plugins directory. However, I am experiencing problems getting generator-core to load the modules from my plugin. I have detailed the issue thoroughly on SO, but here it is for completeness' sake.


I've installed socket.io as a dependency in the plugins/generator-starter directory:

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'

For context: This is in the middle of working on Davide Barranca's Native Photoshop Apps video course—Lesson No.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.


So, even though socket.io is installed in the generator/plugins/generator-starter directory, I still receive the Could not load plugin[…] error message. The strict change to generator-core—in terms of which node_modules folders it uses—has broken my app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions