typescript - 扩展 BsPrefixComponent 进行自定义时找不到 react-bootstrap 模块
问题描述
我正在使用 Create-React-App、Typescript(3.4) 和 react-bootstrap (1.0 beta) 来构建网站。我创建了一个组件 CustomDropdown,它扩展了 BsPrefixComponent。BsPrefixComponent 是从 'react-bootstrap/helpers' 导入的。但是,这无法通过错误消息编译:
编译失败。
./src/CustomDropDown.tsx
未找到模块:无法解析 'path\to\my\project\bs\src' 中的 'react-bootstrap/helpers'
这是我的代码:
import React, { Component } from 'react';
import { BsPrefixComponent } from 'react-bootstrap/helpers';
interface IProps {
name: string;
}
export default class CustomDropDown extends BsPrefixComponent<'div', IProps> {
render() {
return (
<div>
{this.props.name}
</div>
)
}
}
奇怪的是,当使用手动编译时tsc --build tsconfig.js --traceResolution
,我没有看到任何错误。我检查了模块解析日志,“react-bootstrap/helpers”已成功解析。
此外,我的 VSCode 编辑器中没有显示错误。
但是,使用npm start
or时失败了npm run build
。
那么,这是自定义 react-bootstrap 组件的错误方法,还是存在错误?
解决方案
推荐阅读
- text - 如何使用 MediaQuery 为 Flutter 中的文本设置 scaleFactor?
- asp.net - Web API Post 给我错误
- c# - 在 WPF 中动态地将按钮绑定到数据网格
- javascript - 如何从异步函数中提取输出 - react-native?
- list - 定义范围为有序列表的属性
- google-cloud-platform - gcloud compute scp 找不到文件存储实例
- html - 仅突出显示当前悬停的嵌套列表项
- android - Retrofit、Volley 和 HttpURLConnection 不同的响应
- python - 高效读取 WARC 文件
- haskell - haskell 从“脚本”文件加载数据