首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到模块RecipeStyle.css

找不到模块RecipeStyle.css
EN

Stack Overflow用户
提问于 2021-02-12 01:51:20
回答 1查看 19关注 0票数 0

我创建了一个css文件,并希望它包含在jsx文件中。我安装了css加载器、样式加载器和babel。我在脚本中导入了css文件,但它显示了错误消息: can not find moudle ./...

但是为什么呢?

我看了一些教程,学习了所有的东西,我甚至删除了node modules文件夹,并用npm install重新加载了它。

Recipe.jsx

代码语言:javascript
复制
import React from 'react';
import { IngredientFormPart } from './IngredientFormPart';

import './RecipeStyle.css';

export class RecipeForm extends React.Component {
    render() {
        return (
            <form>
                <label>
                    Name des Rezepts
                    <input
                        id="recipeID"
                        type="text"
                        />
                </label>
                <label>
                    <IngredientFormPart />
                </label>
            </form>
        )
    }
}

webpack.config.js

代码语言:javascript
复制
var path    = require('path');
var hwp     = require('html-webpack-plugin');

module.exports = {
    entry: path.join(__dirname, '/src/index.jsx'),
    output: {
        filename: 'build.js',
        path: path.join(__dirname, '/dist')
    },
    module: {
        rules: [
          {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: {
              loader: 'babel-loader'
            }
          },
          {
            test: /\.css$/,
            exclude: /node_modules/,
            use: [
              'style-loader',
              'css-loader'
            ]
          }
        ]
      },
      resolve: {
        extensions: [ '.js', '.jsx', 'css' ]
      },
    plugins:[
        new hwp({template:path.join(__dirname, '/src/index.html')})
    ]
}

.babel配置

代码语言:javascript
复制
{
    "presets": ["@babel/preset-react", "@babel/preset-env"],
    "plugins": ["@babel/plugin-transform-react-jsx"]
}

package.json

代码语言:javascript
复制
{
  "name": "react-state",
  "version": "1.0.0",
  "description": "ddd ",
  "main": "index.js",
  "scripts": {
    "start": "webpack serve --mode development --open --hot",
    "build": "webpack --mode production",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@babel/preset-env": "^7.12.13",
    "css-loader": "^5.0.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "style-loader": "^2.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.13",
    "@babel/preset-react": "^7.12.13",
    "babel-loader": "^8.2.2",
    "html-webpack-plugin": "^5.0.0",
    "webpack": "^5.20.2",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-02-12 02:47:31

尝试将resolve.extensions中的"css"更改为".css"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66160075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档