Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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
Reactjs React.js中的CSS模块不加载_Reactjs_Webpack - Fatal编程技术网

Reactjs React.js中的CSS模块不加载

Reactjs React.js中的CSS模块不加载,reactjs,webpack,Reactjs,Webpack,我正在学习React.js,并且在课程中使用UDE。问题是,自从课程完成后,React已经更新,CSS模块也发生了变化。我试图进行研究并编写代码,但这些类似乎不适用。我在浏览器中使用inspect进行了检查,在React选项卡下(安装了扩展名)显示className={undefined}。在inspector选项卡下,它显示 <div>...</div> 编辑: webpack.config.dev.js的第143至150行: 文件在这里 在react的新版本中,应该

我正在学习React.js,并且在课程中使用UDE。问题是,自从课程完成后,React已经更新,CSS模块也发生了变化。我试图进行研究并编写代码,但这些类似乎不适用。我在浏览器中使用inspect进行了检查,在React选项卡下(安装了扩展名)显示className={undefined}。在inspector选项卡下,它显示

<div>...</div>
编辑: webpack.config.dev.js的第143至150行: 文件在这里


在react的新版本中,应该是这样的:

test: cssRegex,
              exclude: cssModuleRegex,
              use: getStyleLoaders({
                modules: true,
                modules: {
                  localIdentName: "[name]__[local]__[hash:base64:5]",
                },
                importLoaders: 1,
旧版本:

test: /\.css$/,
    optio`enter code here`ns: {
      importLoaders: 1,
      modules: true,
       localIdentName: '[name]__[local]__[hash:base64:5]'
    },
   

您是否更新了
webpack.config.js
以使css模块正常工作?我有两个文件,一个prod和一个dev。它们经常更改。我曾经在test:cssRegex中使用过它,现在它是test:/\.css$/。我试过了,但没有成功。我的反应是16.8.6。它们似乎随着每一个小的更新而改变。你需要提交你的dev网页包配置。特别是说resolve:'css$'之类的部分。我读到您也可以将.module扩展用于非弹出的react项目。我创建了一个新项目,但它不工作。我设法使它与一个未弹出的应用程序一起工作。我进入package.json,将react脚本的版本更新为2.0.0,并运行了npm安装。在新版本中,我认为如果您在webpack文件中手动启用模块,那么应该在没有模块扩展的情况下运行。
    test: /\.css$/,
    options: {
      importLoaders: 1,
      modules: true,
       localIdentName: '[name]__[local]__[hash:base64:5]'
    },
    loader: 'style!css?importLoaders=1!postcss'
  },
test: cssRegex,
              exclude: cssModuleRegex,
              use: getStyleLoaders({
                modules: true,
                modules: {
                  localIdentName: "[name]__[local]__[hash:base64:5]",
                },
                importLoaders: 1,
test: /\.css$/,
    optio`enter code here`ns: {
      importLoaders: 1,
      modules: true,
       localIdentName: '[name]__[local]__[hash:base64:5]'
    },