docs: update create plugin docs (#1953)

* docs: update create plugin docs

Closes #1945 

This updates the documentation to add some troubleshooting to the [Create a Plugin page](https://docs.medusajs.com/advanced/backend/plugins/create)

* Add new section to plugin documentation and updated existing content

* Update docs/content/advanced/backend/plugins/create.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

* Update docs/content/advanced/backend/plugins/create.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

* Update docs/content/advanced/backend/plugins/create.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

* Update docs/content/advanced/backend/plugins/create.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
This commit is contained in:
Richard Ward
2022-08-01 18:07:42 +03:00
committed by GitHub
co-authored by Shahed Nasser
parent f5a42c43fd
commit 2b574185ca
@@ -22,6 +22,10 @@ Where `medusa-plugin-custom` is the name of the plugin youre creating. In Med
By convention, all plugin names start with `medusa` followed by a descriptive name of what the plugin does. For example, the Stripe plugin is named `medusa-payment-stripe`. By convention, all plugin names start with `medusa` followed by a descriptive name of what the plugin does. For example, the Stripe plugin is named `medusa-payment-stripe`.
### Rename Project Name
Update the `name` field in the `package.json` file to the name of your plugin. This should be the same name that you chose when running the `medusa new` command.
### Project Structure ### Project Structure
The command above creates a new directory `medusa-plugin-custom` that holds essentially the same codebase you would have for a Medusa server. This is because a plugin has the same directory structure as a Medusa server. The command above creates a new directory `medusa-plugin-custom` that holds essentially the same codebase you would have for a Medusa server. This is because a plugin has the same directory structure as a Medusa server.
@@ -266,6 +270,50 @@ Finally, start your server and test your plugins functionalities:
npm run start npm run start
``` ```
### Troubleshoot Errors
#### Error: The class must be a valid service implementation
Please make sure that your plugin is following the correct structure. If the error persists then please try the following fix:
```bash npm2yarn
cd <SERVER_PATH>/node_modules/medusa-interfaces
npm link
cd <PLUGIN_PATH>
rm -rf node_modules/medusa-interfaces
npm link medusa-interfaces
npm link
cd <SERVER_PATH>
npm link your-plugin
```
Where `<SERVER_PATH>` is the path to your Medusa server and `<PLUGIN_PATH>` is the path to your plugin.
This links the `medusa-interfaces` package from your `medusa-backend` to your plugin directory and then links your plugin to your `medusa-backend`.
#### APIs not loading
If the APIs you added to your Medussa server are not loading then please try the following steps:
```bash npm2yarn
cd <PLUGIN_PATH>
rm -rf node_modules
cd <SERVER_PATH>/node_modules/<PLUGIN_NAME>
npm install
cd <PLUGIN_PATH>
npm build
cd <SERVER_PATH>
npm start
```
Where `<SERVER_PATH>` is the path to your Medusa server, `<PLUGIN_PATH>` is the path to your plugin and `<PLUGIN_NAME>` is the name of your plugin as it is in your plugin `package.json` file.
:::note
It is safe to ignore any `cross-env: command not found` error you may receive.
:::
## NPM Ignore File ## NPM Ignore File
Not all files that you use while developing your plugin are necessary to be published. Not all files that you use while developing your plugin are necessary to be published.