简体   繁体   English

将npm与react一起使用并输出到浏览器时出现问题

[英]Issues when using npm with react and outputting to the browser

I am attempting to view a basic react js file in the browser and developer panel but I am getting weird errors, does anyone know what is happening? 我试图在浏览器和开发人员面板中查看基本的js文件,但出现了奇怪的错误,有人知道发生了什么吗? I have two files, app.js and projects.js. 我有两个文件,app.js和projects.js。 I downloaded react using the npm with node.js cmd. 我使用带有node.js cmd的npm下载了react。

APP.JS APP.JS

import React, { Component } from 'react';
import projects from './components/projects';

class App extends Component {
  render() {


 return (
      <div className="App">
        My App
      <projects />
    );
  }
}

export default App;

PROJECTS.JS 项目库

import React, { Component } from 'react';

class projects extends Component {
  render() {
    return (
      <div className="projects">
        My Projects
      </div>
    );
  }
}

export default projects;

For some reason when I check the browser on localhost and the developer tools I get the following error message... 由于某些原因,当我检查本地主机上的浏览器和开发人员工具时,收到以下错误消息...

Failed to compile
./src/App.js
Syntax error: C:/Users/Samuel/Desktop/reactmanager/src/App.js: Unterminated JSX contents (9:18)

   7 |       <div className="App">
   8 |         My App
>  9 |       <projects />
     |                   ^
  10 |     );
  11 |   }
  12 | }
This error occurred during the build time and cannot be dismissed.
I also keep having the file path pop up in my code.


2ND ISSUE:

index.js:2178 Mixpanel error: "mixpanel" object not initialized. Ensure you are using the latest version of the Mixpanel JS Library along with the snippet we provide.

NOTE:I am using sublime text 3.

Any idea?

First every react component needs to have the first capital letter, and the you forgot close the div 首先,每个react组件都需要有第一个大写字母,而您忘了关闭div

 import React, { Component } from 'react'; import Projects from './components/projects'; class App extends Component { render() { return ( <div className="App"> My App <Projects /> </div> ); } } export default App; 

 import React, { Component } from 'react'; class Projects extends Component { render() { return ( <div className="projects"> My Projects </div> ); } } export default Projects; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM