question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax error on IE11 when v3.4.1 is bundled by webpack

See original GitHub issue

I have just updated from version 3.3 to 3.4 and noticed that index.cjs.js is missing. index.cjs.js worked on IE11, but syntax error occurs version 3.4 index.js

Our project has to continue to support IE11… After version 3.4, is the only way to support it to transpile index.js by itself?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tt4gcommented, Apr 9, 2021

What we have in 3.4.1 is: zustand/index.js is cjs for old browsers and zustand/esm/index.js is esm for modern browsers.

v3.3 used the following webpack aliases.

resolve: {
    extensions: [".ts", ".tsx", ".js", ".jsx"],
    modules: ["node_modules"],
    alias: {
        zustand: path.resolve(__dirname, "node_modules/zustand/index.cjs.js"),
    },
},

I guess mainFields or direct path is a way to go for IE11 with webpack.

As of now, the following two settings worked with IE11.

Use webpack resolve alias:
resolve: {
    extensions: [".ts", ".tsx", ".js", ".jsx"],
    modules: ["node_modules"],
    alias: {
        zustand: path.resolve(__dirname, "node_modules/zustand/index.js"),
    },
},
Use babel (transpile):
module: {
      rules: [
        {
          test: /\.jsx?$/,
          include: [
            path.resolve(__dirname, "src"), // project source root.
            path.resolve("node_modules/zustand/"), // transpile for IE11 support.
          ],
          use: [{
            loader: "babel-loader"
          }],
        },
}

IMO: webpack resolve alias may be the best workaround. This way, even if webpack prioritizes ES modules, the same files will always be bundled. Transpiling with babel changes the post-transpiling state depending on the module resolved by webpack.

1reaction
tt4gcommented, Apr 9, 2021

I think this is a minor issue as IE11 will be out of support for many products by August 2021.

I’m going to close it because there are workarounds.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax error in IE11 with Webpack, Babel and React
I'm getting a Syntax Error in my React + Redux project in Internet Explorer 11, but I have no idea why it's caused....
Read more >
Syntax error 'SCRIPT1002' using internet explorer 11
I am facing an issue with the browser support in IE 11 of my reactjs project. Here is my code sample. What I...
Read more >
Syntax error in IE11 with React + Babel + Webpack – iTecNote
I'm trying to get my React App with ES2015 functionalities running in IE >= 11 using Webpack + Babel. The setup is custom,...
Read more >
To v5 from v4 - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
IE 11 Syntax error - Get Help - Vue Forum
The code apparantly was not transpiled to ES5 by babel, but should be - that's how the webpack template is configured. Chekc the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found