Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React.js:元素类型无效:_Javascript_Reactjs_Material Ui - Fatal编程技术网

Javascript React.js:元素类型无效:

Javascript React.js:元素类型无效:,javascript,reactjs,material-ui,Javascript,Reactjs,Material Ui,我正在VS2019中创建一个示例react.js项目 我的Index.js import 'bootstrap/dist/css/bootstrap.css'; import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import { ConnectedRouter } from 'react-router-redux'; import { creat

我正在VS2019中创建一个示例react.js项目

我的Index.js

import 'bootstrap/dist/css/bootstrap.css';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'react-router-redux';
import { createBrowserHistory } from 'history';
import configureStore from './store/configureStore';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

// 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.initialReduxState;
const store = configureStore(history, initialState);

const rootElement = document.getElementById('root');

ReactDOM.render(
  <Provider store={store}>
    <ConnectedRouter history={history}>
      <App />
    </ConnectedRouter>
  </Provider>,
  rootElement);

registerServiceWorker();
PAckage.json

"name": "React_Material_UI",
"version": "0.1.0",
"private": true,
"dependencies": {
  "bootstrap": "^4.3.1",
  "jquery": "3.3.1",
  "react": "^16.0.0",
  "react-dom": "^16.0.0",
  "react-redux": "^5.0.6",
  "react-router-bootstrap": "^0.24.4",
  "react-router-dom": "^4.2.2",
  "react-router-redux": "^5.0.0-alpha.8",
  "react-scripts": "^1.1.5",
  "reactstrap": "^6.3.0",
  "redux": "^3.7.2",
  "redux-thunk": "^2.2.0",
  "rimraf": "^2.6.2",
},
"devDependencies": {
  "ajv": "^6.0.0",
  "babel-eslint": "^7.2.3",
  "cross-env": "^5.2.0",
  "eslint": "^4.1.1",
  "eslint-config-react-app": "^2.1.0",
  "eslint-plugin-flowtype": "^2.50.3",
  "eslint-plugin-import": "^2.14.0",
  "eslint-plugin-jsx-a11y": "^5.1.1",
  "eslint-plugin-react": "^7.11.1"
},
"eslintConfig": {
  "extends": "react-app"
},
"scripts": {
  "start": "rimraf ./build && react-scripts start",
  "build": "react-scripts build",
  "test": "cross-env CI=true react-scripts test --env=jsdom",
  "eject": "react-scripts eject",
  "lint": "eslint ./src/"
}

有什么线索吗?

尝试在
MyApp.js

import React, { Component } from 'react'
import { NavBar } from './components/NavBar'
import CoursesList from './components/CourseList'


export default class App extends React.Component {

    render() {
        return (
            <div>
                <NavBar />
                <CoursesList />
            </div>
        )
    }
}
import React,{Component}来自“React”
从“./components/NavBar”导入{NavBar}
从“./components/CourseList”导入课程列表
导出默认类App扩展React.Component{
render(){
返回(
)
}
}

您在问题中编写了
Navbar.js
。请确保您的文件是
NavBar.js
,因为这就是您的代码中要导入的内容。如果不太麻烦的话,您可以共享您的package.json内容吗?因为你的代码看起来不错。但是在你的依赖关系中,我看不到对material ui的引用应该是“依赖关系”:{“@material ui/core”:“4.4.0”,你能//用npm npm安装@material ui/core//用Thread Thread add@material ui/core//你似乎是个初学者,所以这里有一些提示。1)你可以直接使用组件而不是React。组件,因为你已经导入了它。2)尽量避免在React中使用JQuery,因为它会损害React的功能wn引导程序称为Reactstrap或React引导程序。由于正常引导程序3,4使用jquery,因此不建议也使用它
"name": "React_Material_UI",
"version": "0.1.0",
"private": true,
"dependencies": {
  "bootstrap": "^4.3.1",
  "jquery": "3.3.1",
  "react": "^16.0.0",
  "react-dom": "^16.0.0",
  "react-redux": "^5.0.6",
  "react-router-bootstrap": "^0.24.4",
  "react-router-dom": "^4.2.2",
  "react-router-redux": "^5.0.0-alpha.8",
  "react-scripts": "^1.1.5",
  "reactstrap": "^6.3.0",
  "redux": "^3.7.2",
  "redux-thunk": "^2.2.0",
  "rimraf": "^2.6.2",
},
"devDependencies": {
  "ajv": "^6.0.0",
  "babel-eslint": "^7.2.3",
  "cross-env": "^5.2.0",
  "eslint": "^4.1.1",
  "eslint-config-react-app": "^2.1.0",
  "eslint-plugin-flowtype": "^2.50.3",
  "eslint-plugin-import": "^2.14.0",
  "eslint-plugin-jsx-a11y": "^5.1.1",
  "eslint-plugin-react": "^7.11.1"
},
"eslintConfig": {
  "extends": "react-app"
},
"scripts": {
  "start": "rimraf ./build && react-scripts start",
  "build": "react-scripts build",
  "test": "cross-env CI=true react-scripts test --env=jsdom",
  "eject": "react-scripts eject",
  "lint": "eslint ./src/"
}
import React, { Component } from 'react'
import { NavBar } from './components/NavBar'
import CoursesList from './components/CourseList'


export default class App extends React.Component {

    render() {
        return (
            <div>
                <NavBar />
                <CoursesList />
            </div>
        )
    }
}