ant-design / ant-design-mobile

Essential UI blocks for building mobile web apps.
https://mobile.ant.design
MIT License
11.65k stars 2.4k forks source link

create-react-app构建的旧项目安装了antd-mobile-v2正常,但antd-mobile报错 #5218

Closed zmhweb closed 2 years ago

zmhweb commented 2 years ago

Version of antd-mobile

^5.12.5

Operating system and its version

No response

Browser and its version

No response

Sandbox to reproduce

No response

What happened?

image

引入任意一个组件都报错

image

Relevant log output

No response

zmhweb commented 2 years ago

package.json

{
    "name": "sd_incubator",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "ahooks": "^2.9.3",
        "antd-mobile": "^5.12.5",
        "antd-mobile-icons": "^0.2.2",
        "antd-mobile-v2": "^2.3.4",
        "autoprefixer": "7.1.1",
        "axios": "^0.18.0",
        "babel-core": "6.25.0",
        "babel-eslint": "7.2.3",
        "babel-jest": "20.0.3",
        "babel-loader": "7.0.0",
        "babel-preset-react-app": "^3.0.1",
        "babel-preset-react-native-stage-0": "^1.0.1",
        "babel-runtime": "6.23.0",
        "case-sensitive-paths-webpack-plugin": "2.1.1",
        "chalk": "^2.1.0",
        "crypto-js": "^3.1.9-1",
        "css-loader": "0.28.4",
        "dotenv": "4.0.0",
        "echarts": "^5.0.0",
        "eslint": "3.19.0",
        "eslint-config-react-app": "^1.0.5",
        "eslint-loader": "1.7.1",
        "eslint-plugin-flowtype": "2.34.0",
        "eslint-plugin-import": "2.2.0",
        "eslint-plugin-jsx-a11y": "5.0.3",
        "eslint-plugin-react": "7.1.0",
        "extract-text-webpack-plugin": "2.1.2",
        "file-loader": "0.11.2",
        "font-awesome": "^4.7.0",
        "fs-extra": "3.0.1",
        "global": "^4.3.2",
        "gulp": "^3.9.1",
        "html-to-draftjs": "^1.0.1",
        "html-webpack-plugin": "2.29.0",
        "immutability-helper": "^2.6.4",
        "immutable": "^3.8.1",
        "isomorphic-fetch": "^2.2.1",
        "jest": "20.0.4",
        "js-cookie": "^2.2.1",
        "lodash": "^4.17.10",
        "mockjs": "^1.1.0",
        "object-assign": "4.1.1",
        "path-to-regexp": "^2.2.0",
        "postcss-flexbugs-fixes": "3.0.0",
        "postcss-loader": "2.0.6",
        "promise": "7.1.1",
        "react": "^17.0.1",
        "react-bmap": "^1.0.69",
        "react-color": "^2.13.5",
        "react-custom-scrollbars": "^4.2.1",
        "react-dev-utils": "^3.0.2",
        "react-dnd": "^2.4.0",
        "react-dnd-html5-backend": "^2.4.1",
        "react-dom": "^17.0.1",
        "react-draft-wysiwyg": "^1.10.12",
        "react-error-overlay": "^1.0.9",
        "react-infinite-scroller": "^1.1.4",
        "react-loadable": "^5.3.1",
        "react-redux": "^5.0.5",
        "react-resizable": "^1.7.2",
        "react-router": "^4.1.2",
        "react-router-config": "^1.0.0-beta.3",
        "react-router-dom": "^4.1.2",
        "react-router-redux": "^4.0.8",
        "redux": "^3.7.2",
        "redux-logger": "^3.0.6",
        "redux-saga": "^0.16.0",
        "redux-thunk": "^2.2.0",
        "reqwest": "^2.0.5",
        "scp2": "ninja",
        "ssh2": "^0.5.5",
        "style-loader": "0.18.2",
        "styled-components": "^5.2.1",
        "svg-injector": "^1.1.3",
        "sw-precache-webpack-plugin": "^0.11.4",
        "url-loader": "0.5.9",
        "webpack": "^2.6.1",
        "webpack-dev-server": "^2.7.1",
        "webpack-manifest-plugin": "1.1.0",
        "whatwg-fetch": "2.0.3"
    },
    "scripts": {
        "start": "node scripts/start.js",
        "build": "node scripts/build.js",
        "test": "node scripts/test.js --env=jsdom"
    },
    "jest": {
        "collectCoverageFrom": [
            "src/**/*.{js,jsx}"
        ],
        "setupFiles": [
            "<rootDir>/config/polyfills.js"
        ],
        "testMatch": [
            "<rootDir>/src/**/__tests__/**/*.js?(x)",
            "<rootDir>/src/**/?(*.)(spec|test).js?(x)"
        ],
        "testEnvironment": "node",
        "testURL": "http://localhost",
        "transform": {
            "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
            "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
            "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
        },
        "transformIgnorePatterns": [
            "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
        ],
        "moduleNameMapper": {
            "^react-native$": "react-native-web"
        },
        "moduleFileExtensions": [
            "web.js",
            "js",
            "json",
            "web.jsx",
            "jsx"
        ]
    },
    "babel": {
        "presets": [
            "react-app"
        ],
        "plugins": [
            [
                "import",
                {
                    "libraryName": "antd-mobile-v2",
                    "style": "css"
                }
            ],
            "transform-decorators-legacy"
        ]
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "devDependencies": {
        "babel-plugin-import": "^1.2.1",
        "less": "^2.7.2",
        "less-loader": "^4.0.5"
    }
}
awmleer commented 2 years ago

如果方便的话,可以考虑把整个项目打个 zip 包上传上来?这样方便大家帮你排查问题

zmhweb commented 2 years ago

如果方便的话,可以考虑把整个项目打个 zip 包上传上来?这样方便大家帮你排查问题

https://github.com/zmhweb/antd-mobile-example

Dunqing commented 2 years ago

试着跑了下,有几个问题

升级下webpack相关的配置应该就可以了

zmhweb commented 2 years ago

试着跑了下,有几个问题

  • 无法处理拓展运算符...,也就是你贴的图的报错
  • 无法处理 css calc函数 transform: translate(calc(var(--border-width) * -1), calc(var(--border-width) * -1));

升级下webpack相关的配置应该就可以了

谢谢,我重新构建了个,迁移过去了

shilianmalaxiangguo commented 2 years ago

大佬 请问和怎么重构的,怎么迁移的呢,跟你遇到一样的问题,webpack是3.8.x版本,请问升级webpack的版本是多少呢

awmleer commented 2 years ago

@shilianmalaxiangguo 可以考虑去提个 discussion

zmhweb commented 2 years ago

大佬 请问和怎么重构的,怎么迁移的呢,跟你遇到一样的问题,webpack是3.8.x版本,请问升级webpack的版本是多少呢

用create-react-app【注意版本,可以用最新版本的】重新创建,然后把src迁移过去,再把相关依赖安装上去,最后解决下配置的,就差不多了。其余出现的小问题,就得自己排查下。