Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin not detected when installed globally #13

Closed
ramadimasatria opened this issue Nov 1, 2018 · 11 comments
Closed

Plugin not detected when installed globally #13

ramadimasatria opened this issue Nov 1, 2018 · 11 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@ramadimasatria
Copy link

Bug Report

Versions

Version
verdaccio 3.8.5
verdaccio-github-oauth-ui 1.5.2

Expected behavior

I am planning to setup a verdaccio server in a VM. I installed verdaccio and verdaccio-github-oauth-ui globally using npm i -g verdaccio verdaccio-github-oauth-ui.

Observed behaviour

The github-oauth-ui plugin is not detected when I tried running verdaccio

Steps to reproduce

  1. Install verdaccio & verdaccio-github-oauth-ui globally
  2. Update config.yaml
  3. Run verdaccio

Additional context

screen shot 2018-11-01 at 12 46 46

@juanpicado
Copy link

The error might depends of your nodejs set up. I would describe more about your environment otherwise the author of this plugin won’t be able to help you.

@juanpicado
Copy link

Configuration file also helps.

@ramadimasatria
Copy link
Author

I use the LTS version of nodejs (v10.13.0) installed with nvm.
As for configuration, I changed the default config file on ~/.config/verdaccio/config.yaml to match with what described on readme.

storage: ./storage
plugins: ./plugins

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  # enable: false
  title: Verdaccio

uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    # scoped packages
    access: $authenticated
    publish: $authenticated
    proxy: npmjs

  '**':
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    #
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    access: $all

    # allow all known users to publish packages
    # (anyone can register by default, remember?)
    publish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

auth:
  github-oauth-ui:
    org: myorgname

middlewares:
  audit:
    enabled: true
  github-oauth-ui:
    client-id: myclientid
    client-secret: myclientsecret

logs:
  - {type: stdout, format: pretty, level: http}

@n4bb12
Copy link
Owner

n4bb12 commented Nov 1, 2018

Hi Rama,

I tried it using your config and got the same error using npm.
Interestingly it worked for me when installing with yarn.

verdaccio-audit and verdaccio-htpasswd are direct dependencies of verdaccio.
https://github.com/verdaccio/verdaccio/blob/master/package.json#L50
Maybe this is the reason they work, but I'm guessing that any other plugin will also fail to load.

@n4bb12
Copy link
Owner

n4bb12 commented Nov 1, 2018

I've inserted a console.log("tryLoad", path) here:
https://github.com/verdaccio/verdaccio/blob/master/src/lib/plugin-loader.js#L15

Results with npm:

$ verdaccio --config verdaccio.yaml
 warn --- config file  - D:\Projects\n4bb12\tmp-verdaccio\verdaccio.yaml
tryLoad D:\Tools\node\node_modules\verdaccio\build\plugins\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\plugins\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\plugins\verdaccio-github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\plugins\sinopia-github-oauth-ui
tryLoad verdaccio-github-oauth-ui
tryLoad sinopia-github-oauth-ui
tryLoad github-oauth-ui
 error--- plugin not found. try npm install verdaccio-github-oauth-ui
(node:7728) UnhandledPromiseRejectionWarning: Error: "github-oauth-ui" plugin not found
try "npm install verdaccio-github-oauth-ui"
    at Object.keys.map.pluginId (D:\Tools\node\node_modules\verdaccio\build\lib\plugin-loader.js:107:13)
    at Array.map (<anonymous>)
    at loadPlugin (D:\Tools\node\node_modules\verdaccio\build\lib\plugin-loader.js:66:37)
    at Auth._loadPlugin (D:\Tools\node\node_modules\verdaccio\build\lib\auth.js:45:39)
    at new Auth (D:\Tools\node\node_modules\verdaccio\build\lib\auth.js:35:25)
    at defineAPI (D:\Tools\node\node_modules\verdaccio\build\api\index.js:60:16)
    at D:\Tools\node\node_modules\verdaccio\build\api\index.js:146:12
    at Generator.next (<anonymous>)
    at step (D:\Tools\node\node_modules\verdaccio\build\api\index.js:53:191)
    at D:\Tools\node\node_modules\verdaccio\build\api\index.js:53:361
(node:7728) 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(). (rejection id: 1)
(node:7728) [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.

Results with yarn:

$ verdaccio --config verdaccio.yaml
 warn --- config file  - D:\Projects\n4bb12\tmp-verdaccio\verdaccio.yaml
tryLoad C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\plugins\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\verdaccio-github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\sinopia-github-oauth-ui
tryLoad verdaccio-github-oauth-ui
 warn --- Plugin successfully loaded: github-oauth-ui
tryLoad C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\plugins\audit
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\audit
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\verdaccio-audit
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\sinopia-audit
tryLoad verdaccio-audit
 warn --- Plugin successfully loaded: audit
tryLoad C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\plugins\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\verdaccio-github-oauth-ui
tryLoad D:\Projects\n4bb12\tmp-verdaccio\node_modules\sinopia-github-oauth-ui
tryLoad verdaccio-github-oauth-ui
 warn --- Plugin successfully loaded: github-oauth-ui
 warn --- http address - http://localhost:4873/ - verdaccio/3.8.5

Looks like the directory structure is different when installed with yarn vs npm, which probably has an effect on whether they can be require-ed or not.

@juanpicado
Copy link

juanpicado commented Nov 2, 2018

Interesting, verdaccio relies on the node algorithm (https://nodejs.org/api/modules.html#loading_from_node_modules_Folders), so there is no rocket science in our side, it should no be distinction over the node package manager tool is being used. The npm version is also important @ramadimasatria @n4bb12 since might be a bug in their side, which is common time on time.

@ramadimasatria
Copy link
Author

I can confirm the plugin works when installed with yarn, thanks!

I'm currently using npm v6.4.1 and nvm v0.33.11. Will try using other versions and see if the problem persists.

@n4bb12
Copy link
Owner

n4bb12 commented Nov 2, 2018

According to node docs, if I read the algorithm correctly, global node_modules are not searched by default. Only the node installation folder and some default locations in user home are.
https://nodejs.org/api/modules.html#modules_all_together

Using global node_modules in this way seems to not be the intended way of handling dependencies. The online sources I've found suggest using a local installation.

You can, however, add your global node_modules folder to NODE_PATH and the node algorithm will search it. https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

Does making it global give you any advantage? You could still just use a package.json.

Do you have the option to containerize it? Then you could extend the verdaccio docker image:
https://gist.github.com/n4bb12/523e8347a580f596cbf14d0d791b5927

@ramadimasatria
Copy link
Author

I think the algorithm implies that we can't load global modules from locally installed module. But if we used globally installed verdaccio node should be able to load other global modules since they are in the same node_modules directory. CMIIW.

One thing that interests me is other plugins seems to handle global installation just fine. verdaccio-github-oauth is a good example.

I'm setting up verdaccio for a PoC so I installed it globally for the sake of simplicity. I might use local installation or docker later on when I have clearer direction.

Btw, installing with yarn has solved my problem so you can close this issue if you like :)

@n4bb12 n4bb12 closed this as completed Nov 3, 2018
@n4bb12
Copy link
Owner

n4bb12 commented Nov 3, 2018

OK great, will close it then. Glad you got it to work.

node should be able to load other global modules

Apparently not by default. I tried to point that out with reference to the node docs where the node resolve algorithm is described.

other plugins seems to handle global installation just fine

Plugins don't handle installation. They just get require-ed by verdaccio. There is nothing I can hook into or anything like that.

Below you can see that verdaccio-github-oauth doesn't work either.

ACS@AZEESS MINGW64 /D/Projects/__lab/tmp-verdaccio
$ npm i -g verdaccio verdaccio-github-oauth
D:\Tools\node\verdaccio -> D:\Tools\node\node_modules\verdaccio\bin\verdaccio
+ [email protected]
+ [email protected]
added 7 packages from 5 contributors and updated 1 package in 13.832s

$ verdaccio --config verdaccio.yaml
 warn --- config file  - D:\Projects\__lab\tmp-verdaccio\verdaccio.yaml
 error--- plugin not found. try npm install verdaccio-github-oauth
(node:19492) UnhandledPromiseRejectionWarning: Error: "github-oauth" plugin not found
try "npm install verdaccio-github-oauth"
    at Object.keys.map.pluginId (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\lib\plugin-loader.js:106:13)    at Array.map (<anonymous>)
    at loadPlugin (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\lib\plugin-loader.js:65:37)
    at Auth._loadPlugin (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\lib\auth.js:45:39)    at new Auth (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\lib\auth.js:35:25)
    at defineAPI (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\api\index.js:60:16)    at C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\api\index.js:146:12
    at Generator.next (<anonymous>)    at step (C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\api\index.js:53:191)
    at C:\Users\ACS\AppData\Local\Yarn\Data\global\node_modules\verdaccio\build\api\index.js:53:361(node:19492) 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(). (rejection id: 1)
(node:19492) [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.

@n4bb12 n4bb12 added bug Something isn't working invalid This doesn't seem right labels May 28, 2019
@hybridherbst
Copy link

For my future self googling and finding this issue again:

  • must not use--globalwhen installing
  • must call npm install verdaccio-github-oauth-ui from the node_modules verdaccio folder, e.g. /usr/local/lib/node_modules/verdaccio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants