странная ошибка Error: Invalid hook call. React, react-bootstrap

Создаю совершенно новый проект CRA (делал с typescript и без, результат 1)

Мои действия:

  1. npx create-react-app my-app --template typescript

  2. npm install react-bootstrap [email protected]

  3. npm install --save @types/react-bootstrap

  4. изменяю компонент <App/>следующим образом: (вставлю еще картинку.Код как следует не отображается не понятно почему, помечаю его как код, он все равно как текст.) введите сюда описание изображения

    import React from 'react';
    // import Container from 'react-bootstrap/Container'
    // import Row from 'react-bootstrap/Row'
    // import Col from 'react-bootstrap/Col'
    
    import {Container, Row, Col} from 'react-bootstrap'
    
    const App = () => {
        return (
            <>
                <Container>
                    <Row>
                        <Col>1 of 2</Col>
                        <Col>2 of 2</Col>
                    </Row>
                    <Row>
                        <Col>1 of 3</Col>
                        <Col>2 of 3</Col>
                        <Col>3 of 3</Col>
                    </Row>
                </Container>
            </>
        );
    }
    
    export {App}
    
  5. Запускаю проект

  6. Получаю ошибку:

(Если убрать Bootstrap компоненты, то все работает)

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

введите сюда описание изображения


Ответы (1 шт):

Автор решения: Vitalii

К сожалению не получилось воспроизвести ошибку.

  1. npx create-react-app my-app --template typescript
  2. npm install react-bootstrap [email protected]
  3. npm install --save @types/react-bootstrap

Зависимости из package.json:

"bootstrap": "^5.1.3",
"react": "^17.0.2",
"react-bootstrap": "^2.0.2",
"react-dom": "^17.0.2",

Из тех кто сталкивался и решил проблему многие ссылаются на несовместимые версии react и react-dom. Попробуй вот этот вариант: https://github.com/facebook/react/issues/13991#issuecomment-473246217 Но в глобальном смысле это скорее костыль. Причина у тебя где-то в другом. Может ранее устанавливалась другая версия react или create-react-app глобально?

Попробуй разрешить зависимости при помощи yarn вместо npm.

→ Ссылка