gpt4 book ai didi

visual-studio - 找不到模块 'material-ui/styles/MuiThemeProvider' 的声明文件?

转载 作者:搜寻专家 更新时间:2023-10-30 21:12:17 27 4
gpt4 key购买 nike

我正在尝试使用从 npm 安装的 react material-ui 主题,当我包含“从“material-ui/styles/MuiThemeProvider”导入 MuiThemeProvider;”时出现以下错误在 boot-client.tsx 中:

TS7016: Could not find a declaration file for module 'material-ui/styles/MuiThemeProvider'. 'W:/web/WebFront/node_modules/material-ui/styles/MuiThemeProvider.js' implicitly has an 'any' type. Try npm install
@types/material-ui/styles/MuiThemeProvider
if it exists or add a new declaration (.d.ts) file containing declare module
'material-ui/styles/MuiThemeProvider';

我已经尝试了两种建议都无济于事,包括运行命令:npm install -D @types/material-ui。

我在 node_modules 中的@types 文件夹中存在相关类型。

这是我尝试使用它的代码:

import './css/site.css';
import 'bootstrap';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'react-router-redux';
import { createBrowserHistory } from 'history';
import configureStore from './configureStore';
import { ApplicationState } from './store';
import * as RoutesModule from './routes';
let routes = RoutesModule.routes;


import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';


// Create browser history to use in the Redux store
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const history = createBrowserHistory({ basename: baseUrl });

// Get the application-wide store instance, prepopulating with state from the server where available.
const initialState = (window as any).initialReduxState as ApplicationState;
const store = configureStore(history, initialState);

function renderApp() {
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
// and injects the app into a DOM element.
ReactDOM.render(

, document.getElementById('react-app') );

renderApp();

// Allow Hot Module Replacement
if (module.hot) {
module.hot.accept('./routes', () => {
routes = require<typeof RoutesModule>('./routes').routes;
renderApp();
});
}

最佳答案

好吧,我想通了,在“compilerOptions”下的 tsconfig.json 中,visual-studio 默认将其类型设置为 [“webpack-env”],我需要向其添加“material-ui”或选择删除它:https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

关于visual-studio - 找不到模块 'material-ui/styles/MuiThemeProvider' 的声明文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46151688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com