stimulus-rails-nested-form icon indicating copy to clipboard operation
stimulus-rails-nested-form copied to clipboard

Can't import the named export 'Controller' from non EcmaScript module

Open dacook opened this issue 4 months ago • 2 comments

I've added these lines in app/webpacker/controllers/index.js as per the instructions:

import NestedForm from 'stimulus-rails-nested-form';
...
application.register('nested-form', NestedForm);

But getting this compilation error and don't know how to fix it:

./node_modules/stimulus-rails-nested-form/dist/stimulus-rails-nested-form.mjs 42:2-3
Can't import the named export 'Controller' from non EcmaScript module (only default export is available)

Environment

@hotwired/stimulus@^3.2.2 webpack@^4.46.0 rails (7.0.8) node-version 17.9.1 (Edit: I note that this component uses Node 18)

dacook avatar Feb 08 '24 05:02 dacook

This guy had this exactly same problem Check if the module is indeed there as per this question It seems to have to import like this: import NestedForm from 'stimulus-rails-nested-form/dist/stimulus-rails-nested-form.umd.js'

Pauloparakleto avatar Feb 08 '24 12:02 Pauloparakleto

Thank you! This solved it for me.

I wish I could contribute the fix, but can't figure out how. I wonder if this affects all other stimulus-components.

dacook avatar Feb 08 '24 22:02 dacook