Problems when creating a custom plugin

I’ve been trying to create a custom plugin following the official tutorial (https://docs.nocobase.com/development/your-fisrt-plugin) and i’m stuck at this point.

Every time i run “yarn pm create @my-project/plugin-hello” i get the following output:

{"level":"error",
"message":"Cannot find plugin '@my-project/plugin-hello'",
"stack":"Error: Cannot find plugin '@my-project/plugin-hello\n    
at PluginManager.getPackageJson (/app/nocobase/node_modules/@nocobase/server/lib/plugin-manager/plugin-manager.js:134:13)\n    
at async _PluginManager.create (/app/nocobase/node_modules/@nocobase/server/lib/plugin-manager/plugin-manager.js:292:18)\n    
at async _AppCommand.<anonymous> (/app/nocobase/node_modules/@nocobase/server/lib/commands/pm.js:39:5)\n    
at async _AppCommand.parseAsync (/app/nocobase/node_modules/@nocobase/server/node_modules/commander/lib/command.js:935:5)\n    
at async _AsyncEmitter.runAsCLI (/app/nocobase/node_modules/@nocobase/server/lib/application.js:541:23)",
"meta":{},"module":"application","submodule":"","method":"","app":"main","reqId":"fffa994e-9f37-4360-bed9-1b2cc94d6157","dataSourceKey":"main","timestamp":"2025-01-19 01:33:45"}

So i’ve looked into “/app/nocobase/node_modules/@nocobase/server/lib/plugin-manager/plugin-manager.js:134” and it looks like the code is expecting the plugin to be inside the “node_modules” folder instead of “packages/plugin”, that is the path where yarn places the new plugin folder.

I tried hard coding the path to “packages/plugin” in plugin-manager.js but it was unsuccessful.
Also tried older releases of Nocobase, nothing changed.

Try yarn build before yarn start.

Or you can use yarn dev.

The documentation mentioned you can use yarn pm add @my-project/plugin-hello if plugin not shown in plugin manager

1 Like

@caio-ra
I’m facing the exact same issue when trying to create a custom plugin following the tutorial. I get the same error about the plugin not being found in node_modules.

@imantung
I tried your suggestion to run yarn build before yarn start, and even used yarn dev, but unfortunately, the issue persists.

Hello,

Here i works normaly, i type “yarn pm create @leandrojm/test-forum” and nocobase maked the plugin structure as show below.

Try check if you be in the root directory app, update yarn or nocobase.

Environment:
Nocobase: 1.4.16
Node: 20.14
Yarn 1.22
System: MacOS

leandromartins@Xly3 my-nocobase-plugin % yarn pm create @leandrojm/test-forum 
yarn run v1.22.22
$ nocobase pm create @leandrojm/test-forum
WAIT: TypeScript compiling...
Debugger listening on ws://127.0.0.1:65283/f4f69162-42e9-4c40-b98a-bc68cad0d474
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
2025-01-28 01:14:41 [debug] create database instance: {"sync":{"alter":{"drop":false},"force":false},"logging":false,"dialect":"postgres","username":"nocobase","database":"nocobase","port":"5432","timezone":"+08:00","underscored":false,"migrator":{"context":{"app":{"appName":"main","name":"main"}}},"logger":{},"rawTimezone":"+08:00"} meta={"databaseInstanceId":"334WUyf27DbWKS3zizKk2"} module=database app=main reqId=51cd82ab-4d33-4fd7-a8b7-29f70a04911b dataSourceKey=main
2025-01-28 01:14:41 [info]  add app main into supervisor                 module=application submodule=supervisor method=addApp app=main reqId=51cd82ab-4d33-4fd7-a8b7-29f70a04911b dataSourceKey=main
Creating plugin
Write: packages/plugins/@leandrojm/test-forum/.npmignore
Copy:  client.d.ts
Copy:  client.js
Write: packages/plugins/@leandrojm/test-forum/package.json
Write: packages/plugins/@leandrojm/test-forum/README.md
Copy:  server.d.ts
Copy:  server.js
Copy:  src/client/client.d.ts
Write: packages/plugins/@leandrojm/test-forum/src/client/index.tsx
Copy:  src/client/locale.ts
Copy:  src/index.ts
Copy:  src/locale/en-US.json
Copy:  src/locale/zh-CN.json
Copy:  src/server/collections/.gitkeep
Write: packages/plugins/@leandrojm/test-forum/src/server/index.ts
Write: packages/plugins/@leandrojm/test-forum/src/server/plugin.ts

$ nocobase postinstall
VERSION:  1.4.16
The plugin folder is in packages/plugins/@leandrojm/test-forum
2025-01-28 01:14:44 [info]  attempt to add the plugin to the app         module=application app=main reqId=51cd82ab-4d33-4fd7-a8b7-29f70a04911b dataSourceKey=main
2025-01-28 01:14:44 [info]  add plugin [@leandrojm/test-forum]           meta={"name":"@leandrojm/test-forum","packageName":"@leandrojm/test-forum","version":"0.1.0"} module=application app=main reqId=51cd82ab-4d33-4fd7-a8b7-29f70a04911b dataSourceKey=main
Waiting for the debugger to disconnect...
✨  Done in 9.77s.

Hi there, I encountered the same problem when using the Docker-installed version of NocoBase. And I guess you use this version too. Here is my solution.

  1. Check why it cannot find the plugin.
    I looked into the plugin-manager.js file and found the getPackageJson function. I added an output for the packageFile parameter when it encountered an error. I discovered that NocoBase was looking for the plugin in /app/nocobase/node_modules/@my-project/plugin-hello, but the created folder was actually in /app/nocobase/packages/plugins/@my-project/plugin-hello.

  2. Move file to node_modules
    Because of the wrong folder, NocoBase could not find the new plugin. One way to solve this problem is to copy /app/nocobase/packages/plugins/@my-project/plugin-hello to /app/nocobase/node_modules/@my-project/plugin-hello. Alternatively, you can create a symbolic link:

ln -s /app/nocobase/packages/plugins/@my-project /app/nocobase/node_modules


Then try to create a new plugin; it should work now.

I guess this is a problem that only appears in the Docker installation version. @leandro-jm might be using the source code or Git installation, which is why they did not reproduce the issue.

Hello @Raymond,

I have two environment of nocobase, both are same versions: Developer (local) and Test (docker).

  • Developer(Local), i use for developing, tests, debugging and build the plugin. For this version i use the command install (yarn create nocobase-app)

  • Test (Docker), i use for final test, in this case i export plugin version Local in file .tar and import in Nocobase Docker version. For this version i use the docker compose.

  • My Docker version 27.3.1