ActiveStorage imported twice (with actiontext)

Hi, I’m trying to use actiontext and here is the code which I have

import "@rails/actiontext";

import * as ActiveStorage from "@rails/activestorage"
ActiveStorage.start()

But when I see Webpack Bundle Analyzer I find there two imports

Is this expected behaviour? Is there a way to import activestorage.js only once? Thanks.

I suspect you have multiple versions of activestorage being added to your bundle.

Actiontext specifies activestorage as a direct dependency. It’s version 6.0.0-alpha in this commit from master: rails/package.json at 3d428777b05701ca7211a1be723cb1ee0e094bd9 · rails/rails · GitHub

I’m assuming you have also declared activestorage as a dependency in your project as a different version. Both versions of the module are included in your node_modules (and webpack bundle) to avoid conflicts.

You could try specifying the matching version of activestorage in your package.json dependencies or using the resolutions field to override the actiontext behavior (with the caveat that the resolution might not work in your version of actiontext).

In an ideal world perhaps the actiontext package would specify activestorage as a peer dependency instead.

1 Like

Oh, thanks for detailed explanation. You are right there was nested node_modules directory in @rails/actiontext. Using

  "resolutions": {
    "@rails/activestorage": "6.0.2-2"
  }

seems helps at least to remove duplication (simple functionality tests show that everything still works but with warning).

➜  hub git:(refactor) ✗ yarn install
yarn install v1.22.4
[1/4] 🔍  Resolving packages...
warning Resolution field "@rails/activestorage@6.0.2-2" is incompatible with requested version "@rails/activestorage@^6.0.0-alpha"
success Already up-to-date.
✨  Done in 0.64s.

If there will be versions dependencies conflicts will downgrade to to 6.0.0-alpha. Much appreciated!

1 Like