2

Is it possible to entirely disable a node library from loading in IE?

I'm using React.js and a library called Nivo ("@nivo/line": "^0.61.1") to draw a graph. Nivo uses d3 to draw its graphs, and d3 doesn't load correctly when using IE11. An error prints in the console "const must be initialized", which is caused by d3-scale not being in ES5. We're using babel polyfill ("@babel/polyfill": "^7.8.3") to transpile our source code into ES5 which is working fine, but the node_modules aren't being transpiled. I've tried modifying the webpack build module to include the d3-scale library in the transpiling using different variations of the following, but so far this has not been successful:

exclude: [
/node_modules\/(?!d3-scale)/,
/\.stories\.js$/,
/\.test\.js$/,
],

A possible workaround is to disable the graph for IE entirely so that the Nivo library isn't loaded at all, but continues to work for other browsers. Is this possible?

If anyone has any other suggestion for how to solve this please let me know.

Here's a snippet of our graph code:

import React, {Component} from 'react';
import {ResponsiveLine} from '@nivo/line';
import {formatNumbers} from 'Utils/formatNumbers';

...

render() {
    return (
      <>
        { this.props.data.length > 0 ? (
          <ResponsiveLine
           ...
          />
...

This component is then used by another component.

mat_e_44
  • 75
  • 8
  • Does this answer your question? [How to detect IE11?](https://stackoverflow.com/questions/17907445/how-to-detect-ie11) – Drew Reese Mar 13 '20 at 06:30
  • Not really. My question is not about how to detect IE11 but whether I can prevent IE11 from loading a particular component. – mat_e_44 Mar 15 '20 at 22:25
  • Yes, and how would your code determine if it is running in ie11? Detect if app is running on ie11, conditionally render component(s). – Drew Reese Mar 16 '20 at 00:53
  • I tried that, but it didn't solve my issue. Even if I disable the rendering of the component for IE, I still have an import statement that refers to the library and IE still gives an error. It's fixed now. Thanks for your help. – mat_e_44 Mar 16 '20 at 04:57

1 Answers1

0

I've fixed this issue temporarily by using an older version of the nivo/line library which uses an older version of d3-scale. It's not an ideal fix but it works for me until I have time to fix this properly. FYI version 0.55.0 works for me.

mat_e_44
  • 75
  • 8