Closed richardwardza closed 2 years ago
I'm developing a plugin inside a yarn v3 monorepo and the prescribed yarn link
method doesn't work here. The scenario described seems to fit my problem - backend/node_modules/@myscope/myplugin/node_modules/medusa-interfaces
is linked from the plugin inheritance chain which causes instanceof AbstractFileService
to return false, but I'm not finding a way to resolve this using the new yarn. Any suggestions?
const { LocalFileService } = require('@myscope/medusa-file-local');
const { AbstractFileService: fs1 } = require('@myscope/medusa-file-local/node_modules/@medusajs/medusa');
const { AbstractFileService: fs2 } = require('@medusajs/medusa');
const ts = new LocalFileService({}, {});
const isFs1 = ts instanceof fs1;
const isFs2 = ts instanceof fs2;
console.log('isfs1', isFs1); // true
console.log('isfs2', isFs2); // false
Edit: I found the solution for yarn v2+
yarn add @medusajs/medusa@link:<PATH_TO_BACKEND>/node_modules/@medusajs/medusa
yarn add medusa-interfaces@link:<PATH_TO_BACKEND>/node_modules/medusa-interfaces
Caveat: running node with --preserve-symlinks breaks this. I'm not sure how to avoid that.
Preliminary Checks
Issue Summary
When developing a medusa plugin and using the
npm link
method described in the documentation, the user may still end up with the following when starting the medusa backend:This appears to be caused by the plugin having a
node_modules/medusa-interfaces
installation and when the plugin is linked to the backend, the structure ends up as follows:medusa-backend/node_modules/your-plugin/node_modules/medusa-interfaces
When the backend starts it does (
src/loaders/plugins.ts
):BaseService
is being read frommedusa-backend/node_modules/medusa-interfaces
while the plugin is extending frommedusa-backend/node_modules/your-plugin/node_modules/medusa-interfaces
. This makes theloaded.prototype
not an instance ofBaseService
.There is a draft PR to fix this (by allowing
--preserve-symlinks
) here: https://github.com/medusajs/medusa/pull/1860 but I couldn't get the--preserve-symlinks
flag to work.How can this issue be resolved?
Link the
medusa-interfaces
from the backend into the plugin being developed:Now, from
your-plugin
directory you can runnpm run watch
and from your backend you can runnpm run develop
.Changes from the plugin will be visible in the backend whenever the backend reloads.
Are you interested in working on this issue?