Javascript 网页包热开发服务器&x201C;找不到模块”;

Javascript 网页包热开发服务器&x201C;找不到模块”;,javascript,reactjs,webpack,Javascript,Reactjs,Webpack,人们。目前我正在学习Egghead.io上的React,在我的js中导入css文件时发现了一个问题。这是我在js文件中导入css的代码。style.css当前位于同一目录中。我不知道网页包好到足以找出如何解决这个问题 import React from 'react'; import "style.css"; class App extends React.Component { constructor(props) { super(props); this.state =

人们。目前我正在学习Egghead.io上的React,在我的js中导入css文件时发现了一个问题。这是我在js文件中导入css的代码。style.css当前位于同一目录中。我不知道网页包好到足以找出如何解决这个问题

import React from 'react';
import "style.css";
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '/* add your jsx here */',
      output: '',
      err: ''
    }
  }
  update(e) {
    let code = e.target.value;
    try{
      this.setState({
        output: window.Babel
                .transform(code, {presets: ['es2015', 'react']})
                .code,
        err: ''
      })
    }
    catch(err) {
      this.setState({err: err.message})
    }
  }
  render() {
    return (
      <div>
        <header>{this.state.err}</header>
        <div className="container">
          <textarea onChange={this.update.bind(this)} 
                    defaultValue={this.state.input}/>
          <pre>
            {this.state.output}
          </pre>
        </div>
      </div>
    )
  }
}

export default App
从“React”导入React;
导入“style.css”;
类应用程序扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
输入:'/*在此处添加jsx*/',
输出:“”,
错误:“”
}
}
更新(e){
让代码=e.target.value;
试一试{
这是我的国家({
输出:window.Babel
.transform(代码,{presets:['es2015','react']})
.代码,
错误:“”
})
}
捕捉(错误){
this.setState({err:err.message})
}
}
render(){
返回(
{this.state.err}
{this.state.output}
)
}
}
导出默认应用程序
错误文本为:编译失败

在./src/App.js模块中找不到错误:C:\Front-end\projects\React\Reactapp\src中的“style.css”


@./src/App.js 14:0-20

您导入了这样的文件

import "./style.css"
这会告诉Webpack查找名为
style.css
的模块,方法与上面查找
React
module imported行的方法相同

要正确导入样式,请始终使用相对路径导入位置,如下所示


我认为导入有问题,请执行以下操作:导入样式“/style.css”
import "./style.css"