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

/es/redux.mjs Causes Error #3205

Closed
travistrue2008 opened this issue Oct 30, 2018 · 3 comments
Closed

/es/redux.mjs Causes Error #3205

travistrue2008 opened this issue Oct 30, 2018 · 3 comments

Comments

@travistrue2008
Copy link

travistrue2008 commented Oct 30, 2018

What is the current behavior?
New developers on our team who have had our project checked out for a while have a version of redux that has a redux.mjs file in addition to the redux.js file under the /node_modules/redux/es/ directory. Developers with an older working copy of the project only have a single redux.js file in there. The presence of this newer redux.mjs causes an error when we build our project:

Uncaught ReferenceError: require is not defined
at http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:9390:35

ReferenceError: require is not defined
    at Module.../../node_modules/redux/es/redux.mjs (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:9390:35)
    at __webpack_require__ (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:20:30)
    at Module../neb-redux-store.js (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:9579:72)
    at __webpack_require__ (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:20:30)
    at Module../test/all-tests.js (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:9648:77)
    at __webpack_require__ (http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:20:30)
    at http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:84:18
    at http://localhost:9879/base/test/all-tests.js?3ea84986bea7578749183193fb3528688528c8eb:87:10

Both the older developers with a functioning local copy of the project and newer developers whose project won't build are using the same version: v4.0.0. Removing the redux.mjs file fixes the issue. I'm trying to find a more permanent solution on my end, but I was just wondering why redux.mjs shows up for only the newer installs of our project, and not the older ones even though the older devs regularly purge/reinstall packages via npm.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.
This happens when running tests via karma. I'm unfamiliar with karma at the moment, so I can't provide any helpful details. I'm only curious as to why redux.mjs appears in the packages for newer teams vs older teams.

What is the expected behavior?
The /redux/es/ directory shouldn't contain a redux.mjs file as it seems.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
We've tried both v4.0.0 and v4.0.1

@timdorr
Copy link
Member

timdorr commented Oct 30, 2018

This isn't a redux issue. That file doesn't include any reference to require: https://unpkg.com/redux@4.0.1/es/redux.mjs

Something else is up with your build tooling. Nothing should be using that file. It's intended for browsers with the <script type="module> tag.

@timdorr timdorr closed this as completed Oct 30, 2018
@eps1lon
Copy link
Contributor

eps1lon commented Oct 30, 2018

In case you really need to use *.mjs you have to change your webpack config: node-fetch/node-fetch#493 (comment)

Though webpack 4 should support those without further config.

@travistrue2008
Copy link
Author

travistrue2008 commented Oct 30, 2018

This isn't a redux issue. That file doesn't include any reference to require: https://unpkg.com/redux@4.0.1/es/redux.mjs

Something else is up with your build tooling. Nothing should be using that file. It's intended for browsers with the <script type="module> tag.

Alright, thanks for the heads-up! I'm pretty new to webpack, but we are using webpack 4. It sounds like what we want it to do is default to loading the .js version by default rather than the .mjs one.

I checked out that link you posted to see if I could use it as reference to force .js when using , and it already looks like we're doing that. Here's our config:

    webpack: {
      mode: 'development',
      devtool: 'inline-source-map',
      module: {
        rules: [
          {
            test: /\.js/,
            include: path.resolve(dirname),
            exclude: /(test|node_modules)/,
            enforce: 'post',
            use: {
              loader: 'istanbul-instrumenter-loader',
              options: {
                esModules: true
              }
            }
          }
        ]
      },
      plugins: [
        new AllowMutateEsmExports(),
        new webpack.DefinePlugin({
          NEB_API_URL: JSON.stringify('')
        })
      ]
    },

Oddly enough, when I clear out my node_modules, and re-install, /redux/es/index.mjs doesn't get downloaded now for some reason. Only the CommonJS variant exists.

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

3 participants