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

Fix exports field for stimulus package and Webpack 5 #569

Merged
merged 1 commit into from Aug 6, 2022

Conversation

glaszig
Copy link
Contributor

@glaszig glaszig commented Aug 5, 2022

without "." defined as export, webpack 5 won't find the requested module (didn't check with other webpack versions).
this happens because the exports field replaces the root-level "module", "main", "types", etc:

When the exports field is specified, only these module requests are available. Any other requests will lead to a ModuleNotFound Error.

see https://webpack.js.org/guides/package-exports/

this fixes the following error for me:

ERROR in ./app/javascript/packs/application.js 2:0-33
Module not found: Error: Package path . is not exported from package ./node_modules/stimulus (see exports field in ./node_modules/stimulus/package.json)

also, 3.0.1 does not exibit the issue. i guess this issue was introduced with #468.

without "." defined as export, webpack 5 won't find the requested module.
this happens because the exports field replaces the root-level "module", "main", "types", etc:

"When the exports field is specified, only these module requests are available. Any other requests will lead to a ModuleNotFound Error."

see https://webpack.js.org/guides/package-exports/
@chrisgrande
Copy link

I had this issue as well, I just had to change my imports from stimulus to @hotwired/stimulus to fix the resolution.

@marcoroth
Copy link
Member

Hey @glaszig! Thank you for opening this!

You are right, my bad! We'll get this resolved with the next version.

Thank you!

@marcoroth
Copy link
Member

I'm actually surprised that it doesn't complain about the @hotwired/stimulus package. If you look at it's package.json it also doesn't explicitly set the exports.. field.

The only reason why it probably doesn't work in the stimulus case is because we are setting the exports field and thus overriding the default.

In the meantime, you can resolve the issue by using the @hotwired/stimulus package as @chrisgrande mentioned or make an alias for your stimulus package in the package.json like so if you don't want to update all the references throughout your app:

  "stimulus": "npm:@hotwired/stimulus"

@marcoroth marcoroth changed the title fix package exports fields Fix exports field for stimulus package and Webpack 5 Aug 6, 2022
@marcoroth marcoroth merged commit 7da4d25 into hotwired:main Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants