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

Error: Can't resolve './defineProperty' #4174

Closed
alexgleason opened this issue Sep 16, 2021 · 8 comments
Closed

Error: Can't resolve './defineProperty' #4174

alexgleason opened this issue Sep 16, 2021 · 8 comments

Comments

@alexgleason
Copy link

I have upgraded from v4.0.5 to v4.1.1. When compiling with Webpack 5, it fails with this error:

ERROR in ./node_modules/redux/node_modules/@babel/runtime/helpers/esm/objectSpread2.js 1:0-46
Module not found: Error: Can't resolve './defineProperty' in '/home/alex/Projects/soapbox-fe/node_modules/redux/node_modules/@babel/runtime/helpers/esm'
Did you mean 'defineProperty.js'?
BREAKING CHANGE: The request './defineProperty' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
resolve './defineProperty' in '/home/alex/Projects/soapbox-fe/node_modules/redux/node_modules/@babel/runtime/helpers/esm'
  using description file: /home/alex/Projects/soapbox-fe/node_modules/redux/node_modules/@babel/runtime/helpers/esm/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/alex/Projects/soapbox-fe/node_modules/redux/node_modules/@babel/runtime/helpers/esm/package.json (relative path: ./defineProperty)
      Field 'browser' doesn't contain a valid alias configuration
      /home/alex/Projects/soapbox-fe/node_modules/redux/node_modules/@babel/runtime/helpers/esm/defineProperty doesn't exist

webpack compiled with 1 error

It seems to be related to this issue: webpack/webpack#11467

Adding the following into my Webpack rules fixes the problem:

  {
    test: /\.m?js/,
    resolve: {
      fullySpecified: false,
    },
  },
@timdorr
Copy link
Member

timdorr commented Sep 16, 2021

This isn't a Redux issue.

@timdorr timdorr closed this as completed Sep 16, 2021
@alexgleason
Copy link
Author

🤔 Did you read webpack/webpack#11467 ?

You're shipping a package.json with "type": "module" but the code is importing modules without the extension.

These are all the same issues. In .mjs files or .js files with a package.json with "type": "module" imports need to be fully specified. This means you need to have an extension.

That how ESM in node.js is defined, and you are opting in into this behavior by using the .mjs extension resp the field in the package.json.

We didn't enforce this behavior in previous versions while this was still experimental in node.js, but it left this status, so I feel ok with enforcing this and pointing out these incorrect packages.

Yes Javascript is insane, everything is everyone's problem and no one's problem. But do you want Redux to work correctly in Webpack 5?

@alexgleason
Copy link
Author

I'm not the first to have this problem and I won't be the last. I'm just the first to report it.

Your incredibly rude and dismissive response makes me wonder why I waste my time. I've already worked around the problem, but the reality is that this is a bug in your software. Just thought you might like to know!

I get it. Open source is hard. People are ungrateful. I know that better than anyone. But come back to Earth for 5 seconds and reread this please.

@timdorr
Copy link
Member

timdorr commented Sep 16, 2021

My man, please take a chill pill. It'll be OK.

We aren't shipping a "type": "module" package. Here's our package.json as it exists on npm: https://unpkg.com/browse/[email protected]/package.json

This is actually a Babel issue, we're just one of the transitive dependencies that brought it to your attention. The good news is it was fixed in babel/babel#10853 and shipped in 7.12.0. Make sure you're using at least that version and you should be good to go.

@alexgleason
Copy link
Author

This seems like a package manager problem, but it doesn't help that redux has "@babel/runtime": "^7.9.2" listed as a dependency when this problem was fixed in v7.12.0.

I'm struggling to make it not put a node_modules folder with an outdated version in there:

Screenshot from 2021-09-16 10-21-49

@markerikson
Copy link
Contributor

I'm kinda confused, because by definition, ^7.9.2 should install the latest at the time that you run the installation, so 7.12 or whatever's out now.

What other versions of @babel/runtime are being requested in your project right now?

@alexgleason
Copy link
Author

It was the lock file. Apparently yarn add redux@latest isn't good enough. yarn upgrade redux (and upgrading a bunch of other deps that way) finally fixed it. Thanks for your help.

@artyom-88
Copy link

Adding @babel/runtime": ">=7.16.7" to yarn resolutions helped to solve the problem.

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

No branches or pull requests

4 participants