Skip to content

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

Closed

Description

@alexgleason

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,
    },
  },

Activity

  1. timdorr commented on Sep 16, 2021

    @timdorr
    Member

    This isn't a Redux issue.

  2. alexgleason commented on Sep 16, 2021

    @alexgleason
    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?

  3. alexgleason commented on Sep 16, 2021

    @alexgleason
    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.

  4. timdorr commented on Sep 16, 2021

    @timdorr
    Member

    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/redux@4.1.1/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.

  5. alexgleason commented on Sep 16, 2021

    @alexgleason
    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

  6. markerikson commented on Sep 16, 2021

    @markerikson
    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?

  7. alexgleason commented on Sep 16, 2021

    @alexgleason
    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.

  8. artyom-88 commented on Jan 27, 2022

    @artyom-88

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions