reactjs - 在 Netlify 上部署的 Gatsby Starter 上安装 'react-bootstrap'

标签 reactjs gatsby yarnpkg contact-form netlify

我对 gatsby 和 React 都很陌生。 我正在制作一个联系表单,并希望根据使用 React-bootstrap 中的组件的教程来完成此操作,但是我不知道如何将其安装在我通过 github 存储库部署的 gatsby 启动器上。

我的代码给出一个想法:

import React from 'react';

import Layout from '@common/Layout';
import Navbar from '@common/Navbar';

import Header from '@sections/Header';
import About from '@sections/About'; 
import Footer from '@sections/Footer';

import {Row, Col, Container, Form, Button} from "react-bootstrap" 

const IndexPage = () => (
  <Layout>
    <Navbar />
    <Header />
    <About>
      <Container>
        <Form name= "contact v1" method="post" data-netlify="true" onSubmit="submit">
         <input type="hidden" name="form-name" value="contact v1" />
          <Row>
            <Col>
              <Form.Group>
                <Form.Label>First Name </Form.Label>
                <Form.Control required size="lg" type="text"/>
              </Form.Group>
            </Col>
            <Col>
              <Form.Group>
                <Form.Label>Last Name </Form.Label>
                <Form.Control required size="lg" type="text"/>
              </Form.Group>
            </Col>
          </Row>
          <Form.Group>
                <Form.Label>How can we help? </Form.Label>
                <Form.Control required as="textarea" rows="3" placeholder="What do you do?"/>
          </Form.Group>
          <Button type="submit"> Submit </Button>
        </Form>
      </Container>
    </About>
                
    <Footer />
  </Layout>
);

export default IndexPage; 

这是我在 Netlify 上部署时出现的错误

3:08:08 PM: failed Building production JavaScript and CSS bundles - 15.912s
3:08:08 PM: error Generating JavaScript bundles failed
3:08:08 PM: Can't resolve 'react-bootstrap' in '/opt/build/repo/src/pages'
3:08:08 PM: If you're trying to use a package make sure that 'react-bootstrap' is installed. If you're trying to use a local file make sure that the path is correct.
3:08:08 PM: not finished Generating image thumbnails - 20.910s
3:08:08 PM: error Command failed with exit code 1.
3:08:08 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

最佳答案

正如您在 docs 中看到的那样,只需运行:

npm install react-bootstrap bootstrap

请记住,当您这样做时:

import {Row, Col, Container, Form, Button} from "react-bootstrap" 

您将从 node_modules 目录导入组件,特别是从 react-bootstrap 文件夹导入组件,因此您需要首先安装依赖项。

关于reactjs - 在 Netlify 上部署的 Gatsby Starter 上安装 'react-bootstrap',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66157562/

相关文章:

javascript - 使用调用者组件的相同属性

sorting - 客户端 graphQL 排序 - 可以添加一个将 graphql 查询排序从 ASC 反转为 DESC 的按钮吗?

node.js - yarn 警告 "> bootstrap@4.x.x"未满足对等依赖性 "jquery@1.9.1 - 3"

Webpack 和 Yarn 工作区/Lerna

javascript - 如何根据键在 React JS 中创建动态表?

javascript - react : How to use arrow up/down to select previous/next item in a scroll list and make the list scroll to keep the selected element on screen

node.js - 从 Gatsby 中删除 Node

node.js - 强制忽略 npm/yarn 安装的一个依赖项的依赖项

arrays - 使用索引在数组中添加项目 - React redux 和 redux-saga

javascript - Gatsby Markdown 图像卡在模糊的范围内