简体   繁体   English

ReactJS 将代理添加到 package.json css 模块停止工作

[英]ReactJS when add proxy to package.json css modules stop working

I add in my package.json proxy for making request to server runing on other port.我添加了我的 package.json 代理,用于向在其他端口上运行的服务器发出请求。

after that, my module css styles stop working, in the devTools i found that the styles are loading well, but classnames for DOM elements are not loading at all.之后,我的模块 css styles 停止工作,在 devTools 中我发现 styles 加载良好,但 DOM 元素的类名根本没有加载。

How it looks now:现在的样子:

在此处输入图像描述

How it should be:它应该如何:

在此处输入图像描述

some page code:一些页面代码:

import styles from "./LoginPage.module.css";
export default function LoginPage() {
 return (
          <div className={styles.LoginPage}>
         </div>
     );
}

Here is my package.json:这是我的 package.json:

{
    "name": "job-bot-admin-panel",
    "version": "0.1.0",
    "private": true,
    "proxy": "http://localhost:8000/",
    "dependencies": {
        "@reduxjs/toolkit": "^1.8.1",
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.5.0",
        "@testing-library/user-event": "^7.2.1",
        "http-proxy-middleware": "^2.0.4",
        "multiselect-react-dropdown": "^2.0.21",
        "react": "^18.0.0",
        "react-dom": "^18.0.0",
        "react-redux": "^7.2.8",
        "react-router-dom": "^6.3.0",
        "react-scripts": "^0.9.5",
        "react-select": "^5.2.2",
        "web-vitals": "^2.1.4"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }

your filename is incorrect.你的文件名不正确。 for css modules you don't need to add .module to the filename, just name it LoginPage.css and import it with that same name and your styles should be fine.对于 css 模块,您不需要将.module添加到文件名中,只需将其命名为LoginPage.css并使用相同的名称导入它,您的 styles 应该没问题。 React is getting confused with your module filename. React 与您的module文件名混淆了。

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

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