0

In our application, we used the library of icons, which was created by the first developers and was no longer supported by the new version of the react (16.0 and higher)

We decided to leave their previous look, just by slightly changing the code so that it worked, and to make it as a Component.

Here is how it look's now:

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import * as icons from 'icons';

class Icon extends Component {
    static propTypes = {
        type: PropTypes.oneOf(Object.keys(icons)).isRequired
    };

    render() {
        const {type, ...other} = this.props;
        const IconComponent = icons[type];

        return IconComponent ? (
            <IconComponent {...other}/>
        ) : null;
    }
}

export * from '/icons';
export default Icon;

In theory, everything should work fine, since other components in this directory are written in a similar way.

But there is an error that I have never faced before:

00:14:58 App /home/cpt/Desktop/prod/local/app/components/Base/Elements/IconSocial/index.js:3
00:14:58 App import _Object$defineProperty from 'babel-runtime/core-js/object/define-property';
00:14:58 App ^^^^^^
00:14:58 App SyntaxError: Unexpected token import

Error points to this line: import * as icons from 'icons';

We use babel-core": "6.26.3"

Tell me, please, what could possibly be? Thanks in advance for any of your advice.

1 Answer 1

1

This is a babel issue. Here you can read about it: https://github.com/babel/babel/issues/2877

Possible solution would be to add that to plugins:

"plugins": [
    ["transform-runtime", { "polyfill": false }]
]
Sign up to request clarification or add additional context in comments.

1 Comment

I didn’t understand how it works, but it helped, thank you very much :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.