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

Local extensions loaded twice when included as package dependency #21926

Open
echocrow opened this issue Mar 20, 2024 · 6 comments
Open

Local extensions loaded twice when included as package dependency #21926

echocrow opened this issue Mar 20, 2024 · 6 comments

Comments

@echocrow
Copy link

echocrow commented Mar 20, 2024

Describe the Bug

When packaging extensions locally and listing them as dependency in package.json, Directus currently will load them twice.

Background:
We've "installed" our local extension packages as dependencies in the Directus app package, so that our monorepo tooling (e.g. Turborepo) picks up on the extensions as dependencies, and knows to build those first before deploying Directus (e.g. to Directus Cloud).

Temp fix is to configure local Directus with e.g. EXTENSIONS_PATH="./null" .
Edit: Pointing the extensions path to an empty directory does bypass this issue, but also prevents extension auto reloading from working.
Edit 2: Another temp fix is to declare local dependencies as optionalDependencies or devDependencies. Repo tools like Turborepo will still pick up the dependencies for tasks, but Directus (checking only dependencies for extensions) will not double-load them.

To Reproduce

./package.json

{
  // ...
  "dependencies": {
    "my-extension": "workspace:^",
    "directus": "^10.10.4",
    "pg": "^8.11.3"
  },
  // ...
}

./extensions/my-extension/package.json

{
  "name": "my-extension":",
  "icon": "extension",
  // ...
}

Then start Directus.

Expected:

  • Info log: INFO: Loaded extensions: my-extension
  • Only one instance of my-extension in the directus_extensions table
  • my-extension listed only once on /admin/settings/extensions
  • Any hooks (e.g. init('app.after', () => ...) registered and fired once

Actual:

  • Info log: INFO: Loaded extensions: my-extension, my-extension
  • Two records of my-extension in the directus_extensions table
  • my-extension listed twice on /admin/settings/extensions
  • Hooks (e.g. init('app.after', () => ...) registered and fired twice

Directus Version

v10.10.4

Hosting Strategy

Self-Hosted (Docker Image)

@robinsonjohn
Copy link

I am also experiencing a similar issue since the release of Directus 10.10.x with the extensions marketplace.

@echocrow
Copy link
Author

minor update, found a temp workaround for us:

instead of declaring local extensions as dependencies (which is currently causing Directus to load them twice), we shifted to listing them as optionalDependencies.

@robinsonjohn
Copy link

In my particular instance, I am using the Sane Image Size plugin, but it does not appear on the newly developed Marketplace.

Therefore, I am adding it as a dependency in my package.json file:

"dependencies": {
    "directus-extension-sane-image-size": "https://github.com/martabitbrain/directus-extension-sane-image-size.git#v1.1.1"
}

...then my install script runs the following:

cp -r ./node_modules/directus-extension-sane-image-size ./extensions

This allows me to keep the extension up to date with the current repository and exclude its files from my version controlled application.

It was working great until the update which included the Marketplace was released. Now, the extension loads as expected as a local extension, but Directus is also loading it as a module, but the module version appears as "missing" (loaded twice).

Screenshot 2024-03-28 at 9 05 25 AM

Screenshot 2024-03-28 at 9 07 18 AM

@echocrow
Copy link
Author

@robinsonjohn hmm, I suspect that custom remove extension not being picked up might be a different bug.

in the meantime, did you try moving directus-extension-sane-image-size into devDependencies or optionalDependencies? I suspect the same workaround may also work for you.

(BTW, you can probably also symlink (ln -s) instead of copy (cp -r) the extension. Not a big difference, but saves from the extra coping, and and re-copying after package updates. - We actually used to symlink all our ./extensions into a custom ./.directus/extensions dir ourselves before v10.10 just in order to not prefix our source foldes with directus-extension- 😅.)

@robinsonjohn
Copy link

@echocrow Thanks for the suggestions. I had attempted to use a symlink, but Directus completely ignored the extensions as if they weren't there. I had to copy the files themselves in order to get it to work.

I'll go back and attempt the devDependencies suggestion...

@br41nslug
Copy link
Member

br41nslug commented Mar 28, 2024

I had attempted to use a symlink, but Directus completely ignored the extensions as if they weren't there.

That is to be expected if you're using docker as you cannot symlink between the container and host OS. So inside the container they really are not there 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 Needs Triage
Development

No branches or pull requests

3 participants