Привет. У меня есть react.js ts с кастомным конфигом webpack для ответа на post запросы,…
- User
Привет. У меня есть react.js ts с кастомным конфигом webpack для ответа на post запросы, так же как будто это get запросы. Вот мой webpack.config.js const path = require('path');
module.exports = { entry: './src/index.tsx', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, module: { rules: [ { test: /.(ts|tsx)/, use: 'ts-loader', exclude: /node_modules/, }, { test: /\.s[ac]ss/i, use: [ 'style-loader', 'css-loader', 'sass-loader', ], }, ], }, resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'], }, devServer: { static: { directory: path.join(__dirname, 'dist'), }, historyApiFallback: true, port: 5000, open: true, setupMiddlewares: (middlewares, devServer) => { // Обработка POST запросов devServer.app.post('*', (req, res) => { res.redirect(req.originalUrl); }); return middlewares; }, }, };
Вот мой package { "name": "report-for-bitrix", "version": "0.1.0", "private": true, "dependencies": { "@types/node": "^22.10.1", "@types/react": "^19.0.1", "@types/react-dom": "^19.0.1", "bx24": "^0.1.3", "cra-template-typescript": "1.2.0", "mobx": "^6.13.5", "mobx-react-lite": "^4.0.7", "react": "^19.0.0", "react-dom": "^19.0.0", "react-scripts": "5.0.1", "sass": "^1.82.0", "semver": "^7.6.3", "typescript": "^5.7.2" }, "scripts": { "start": "webpack serve --mode development", "build": "webpack --mode production" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "@babel/core": "^7.26.0", "@babel/preset-env": "^7.26.0", "@babel/preset-react": "^7.26.3", "@babel/preset-typescript": "^7.26.0", "babel-loader": "^9.2.1", "css-loader": "^7.1.2", "sass-loader": "^16.0.4", "style-loader": "^4.0.0", "ts-loader": "^9.5.1", "webpack": "^5.97.1", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.1.0" } } Вот мой tsconfig { "compilerOptions": { "target": "es5", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "outDir": "./dist", "sourceMap": true, "jsx": "react-jsx" // Используйте 'react' или 'react-jsx' в зависимости от версии React }, "include": [ "src/**/*" // Включает все файлы в папке src ], "exclude": [ "node_modules" // Исключает папку node_modules ] }
Структура проекта ├── /src │ ├── /components │ ├── /Header │ │ ├── index.tsx │ │ └── style.module.scss │ ├── styles.d.ts │ └── index.tsx ├── package.json ├── webpack.config.js └── tsconfig.json
Я получаю ошибку index.tsx:10 Uncaught TypeError: Cannot read properties of undefined (reading 'header')
В компоненте Header import styles from './style.module.scss' console.log(styles); const Index = () => { return ( 123 ); }
- Assistant
- User
Ничего не поменялось
- Assistant
- User
Я переустановил модули. Попробовал убрать .module.scss и сделать просто .scss Ошибка осталась
- Assistant
- User
Да, действительно style.scss .header { width: 100%; height: 100px; background: red; }
import styles from './style.scss' console.log(styles); const Index = () => { return ( 123 ); }
export default Index;
заработал
- Assistant
- User
При добавлении .module.scss Проект выдает ошибку TypeError: Cannot read properties of undefined (reading 'header')
import styles from './style.module.scss' console.log(styles); const Index = () => { return ( 123 ); }
export default Index;
.header { width: 100%; height: 100px; background: red; }
- Assistant
- User
const Index: React.FC = ({children}) => { return ( {children} ); }
export default Index;
Как типизировать children
- Assistant
- User
Как мне вытащить result из такого ответа? { "answer": { "result": { "item": { "id": 197, "xmlId": "", "title": " H 523 CA 790", "createdBy": 1, "updatedBy": 0, "movedBy": 1, "createdTime": "2024-08-02T15:49:10+03:00", "updatedTime": "2024-09-30T16:33:44+03:00", "movedTime": "2024-08-02T15:49:10+03:00", "categoryId": 15, "opened": "N", "previousStageId": "", "begindate": "2024-08-02T03:00:00+03:00", "closedate": "2024-08-09T03:00:00+03:00", "companyId": 0, "contactId": 0, "opportunity": 0, "isManualOpportunity": "N", "taxValue": 0, "currencyId": "RUB", "opportunityAccount": 0, "taxValueAccount": 0, "accountCurrencyId": "RUB", "mycompanyId": 1, "sourceId": "CALL", "sourceDescription": "", "webformId": 0, "ufCrm9_1722599508304": 0, "ufCrm9_1722599588573": " H 523 CA 790", "ufCrm9_1722599606887": "КВ2541427", "ufCrm9_1722602538937": "", "ufCrm9_1723196780": "581", "ufCrm9_1723196812": null, "ufCrm9_1724941182": null, "ufCrm9_1726233073973": "", "assignedById": 51, "lastActivityBy": 1, "lastActivityTime": "2024-08-02T15:49:10+03:00", "parentId1040": null, "parentId1052": null, "utmSource": null, "utmMedium": null, "utmCampaign": null, "utmContent": null, "utmTerm": null, "observers": [], "contactIds": [], "entityTypeId": 1048 } }, "time": { "start": 1733729364.461282, "finish": 1733729364.507558, "duration": 0.046276092529296875, "processing": 0.022883892059326172, "date_start": "2024-12-09T10:29:24+03:00", "date_finish": "2024-12-09T10:29:24+03:00", "operating_reset_at": 1733729964, "operating": 0 } }, "query": { "method": "crm.item.get", "data": { "entityTypeId": "1048", "id": "197" } }, "status": 200 }
- Assistant