bundle.js:sourcemap:30 Uncaught ReferenceError: Cannot access 'Product' before initialization

Updated at 09-Nov-2022, By samar

bundle.js:sourcemap:30 Uncaught ReferenceError: Cannot access 'Product' before initialization. It means you are trying to call the function before initialization. You have to first initialize the function after that you can call it, otherwise it will give you an error message.

The "Cannot access 'Product' before initialization" error occurs, when a function declared using const is accessed before it was initialized in the scope. To solve the error, make sure to initialize the function before accessing it.

Here we first declare the function using const and access the function after the initialization.

  • Example code to initialize product function and call proptypes on it in react.

    You have to install prop-types using npm install prop-types command after that you have to import proptypes using import PropTypes from 'prop-types'.

    import React from 'react';
    import PropTypes from 'prop-types';
    const Product = (props) => {
        return (
                Product Name : {props.name},
                Product Price : {props.price}
    Product.propTypes = {
        name: PropTypes.string,
        price: PropTypes.number,
    export default Product;

Back to code snippet queries related react