baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
17.33k stars 2.51k forks source link

react18 跑不起来 #4666

Closed duolabmeng6 closed 1 month ago

duolabmeng6 commented 2 years ago
    "amis": "^2.0.0-rc.14",
    "react": "^18.0.0",
    "react-dom": "^18.0.0"

✘ [ERROR] Could not resolve "amis-formula/lib/doc"

    node_modules/amis-ui/esm/components/formula/Editor.js:9:20:
      9 │ import { doc } from 'amis-formula/lib/doc';
        ╵                     ~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "amis-formula/lib/doc" as external to exclude it from the bundle, which will
  remove this error.

5:44:39 AM [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/amis-ui/esm/components/formula/Editor.js:9:20: ERROR: Could not resolve "amis-formula/lib/doc"
    at failureErrorWithLog (/Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:1605:15)
    at /Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:1251:28
    at runOnEndCallbacks (/Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:1034:63)
    at buildResponseToResult (/Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:1249:7)
    at /Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:1358:14
    at /Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (/Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (/Users/chensuilong/Desktop/nodeproject/React/vite-project/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
Vite Error, /node_modules/.vite/deps/react.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/amis.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react-dom_client.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=040af075 optimized info should be defined (x2)
Vite Error, /node_modules/.vite/deps/react.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react-dom_client.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/amis.js?v=040af075 optimized info should be defined
Vite Error, /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=040af075 optimized info should be defined
github-actions[bot] commented 2 years ago

👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

duolabmeng6 commented 2 years ago
npm i --legacy-peer-deps
npm i amis-formula

解决了 不要太坑...

duolabmeng6 commented 2 years ago

跑起来了 没样式...我也不会用 懵逼了

duolabmeng6 commented 2 years ago
import {render as renderAmis} from 'amis';
import axios from 'axios';
import '../node_modules/amis/lib/themes/cxd.css';
import '../node_modules/amis/lib/helper.css';
import '../node_modules/amis/sdk/iconfont.css';
function App() {

    return (
        <div>
            {
                renderAmis(
                    {
                        "type": "page",

                        "body": [
                            {
                                "type": "crud",
                                "syncLocation": false,
                                "api": {
                                    "method": "get",
                                    "url": "/api/articles"
                                },
                                "columns": [
                                    {
                                        "name": "id",
                                        "label": "ID",
                                        "type": "text"
                                    },
                                    {
                                        "name": "title",
                                        "label": "标题",
                                        "type": "text"
                                    },
                                    {
                                        "type": "datetime",
                                        "label": "创建时间",
                                        "name": "created_at"
                                    },
                                    {
                                        "type": "operation",
                                        "label": "操作",
                                        "buttons": [
                                            {
                                                "label": "编辑",
                                                "type": "button",
                                                "level": "link",
                                                "actionType": "drawer",
                                                "drawer": {
                                                    "position": "right",
                                                    "size": "lg",
                                                    "title": "编辑",
                                                    "body": {
                                                        "type": "form",
                                                        "initApi": "/api/articles/${id}/edit",
                                                        "api": "put:/api/articles/${id}",
                                                        "body": [
                                                            {
                                                                "name": "title",
                                                                "label": "标题",
                                                                "type": "input-text"
                                                            },
                                                            {
                                                                "type": "input-rich-text",
                                                                "name": "content",
                                                                "label": "内容"
                                                            }
                                                        ]
                                                    }
                                                }
                                            },
                                            {
                                                "label": "查看",
                                                "type": "button",
                                                "actionType": "dialog",
                                                "level": "link",
                                                "dialog": {
                                                    "title": "查看详情",
                                                    "body": {
                                                        "type": "form",
                                                        "initApi": "/api/articles/${id}/edit",
                                                        "body": [
                                                            {
                                                                "name": "id",
                                                                "label": "ID",
                                                                "type": "static"
                                                            },
                                                            {
                                                                "name": "title",
                                                                "label": "标题",
                                                                "type": "static"
                                                            },
                                                            {
                                                                "type": "input-rich-text",
                                                                "name": "content",
                                                                "label": "内容"
                                                            }
                                                        ]
                                                    }
                                                }
                                            },
                                            {
                                                "type": "button",
                                                "label": "删除",
                                                "actionType": "ajax",
                                                "level": "link",
                                                "className": "text-danger",
                                                "confirmText": "确定要删除?",
                                                "api": "delete:/api/articles/${id}"
                                            }
                                        ]
                                    }
                                ],
                                "bulkActions": [
                                    {
                                        "type": "button",
                                        "level": "danger",
                                        "label": "批量删除",
                                        "confirmText": "确定要删除?",
                                        "actionType": "ajax",
                                        "api": "delete:/api/articles/bulkDelete/${ids|raw}",
                                    }
                                ],
                                "itemActions": [],
                                "features": [
                                    "create",
                                    "filter",
                                    "bulkDelete",
                                    "update",
                                    "view",
                                    "delete"
                                ],
                                "filterColumnCount": 3,
                                "headerToolbar": [
                                    {
                                        "label": "新增",
                                        "type": "button",
                                        "level": "primary",
                                        "actionType": "drawer",
                                        "drawer": {
                                            "position": "right",
                                            "size": "lg",
                                            "title": "新增",
                                            "body": {
                                                "type": "form",
                                                "api": "post:/api/articles",
                                                "body": [
                                                    {
                                                        "type": "input-text",
                                                        "name": "title",
                                                        "label": "标题"
                                                    },
                                                    {
                                                        "type": "input-rich-text",
                                                        "name": "content",
                                                        "label": "内容"
                                                    }
                                                ]
                                            }
                                        }
                                    },
                                    "bulkActions"
                                ],
                                "id": "u:c3167575b83d",
                                "perPageAvailable": [
                                    10
                                ],
                                "messages": {},
                                "filter": {
                                    "title": "查询条件",
                                    "body": [
                                        {
                                            "type": "input-text",
                                            "name": "keywords",
                                            "label": "关键字"
                                        }
                                    ]
                                }
                            }
                        ]
                    },{

                    },{theme:"cxd"}
                )
            }
        </div>
    )
}

export default App
duolabmeng6 commented 2 years ago
factory.js:139 Please implement isCancel. see https://baidu.gitee.io/amis/docs/start/getting-started#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97

不知道啥意思...不会用...样式出来了 事件都没效果 点击都没效果~~

awen1988 commented 2 years ago

必须要实现那3个接口 fetcher isCancel copy

HoseaGuo commented 2 years ago

amis安裝1.x版本的可以

duolabmeng6 commented 2 years ago

amis安裝1.x版本的可以

成功显示了

不过 点击 新增啊 没翻译 点击搜索 没看到附带参数

react_devtools_backend.js:4026 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of QuickEditComponent2 which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node

duolabmeng6 commented 2 years ago

必须要实现那3个接口 fetcher isCancel copy


Are they installed?
Failed to resolve import "amis/lib/components/Toast" from "src/App.tsx". Does the file exist?

跟着demo代码复制...也有很多问题

duolabmeng6 commented 2 years ago

React 中引入 amis 的组件 在 React 环境下使用 amis,还可以直接引入 amis 内置组件,在 amis 项目源码 src/components 下的组件都是标准 React 组件,可以在项目中直接引用,这样就能将 amis 当成纯粹 UI 库来使用。

import {Button} from 'amis/lib/components/index';

<Button
  onClick={() => {}}
  type="button"
  level="link"
  className="navbar-btn"
>
  按钮
</Button>

https://aisuda.bce.baidu.com/amis/zh-CN/docs/extend/ui-library

这个也引用失败..

duolabmeng6 commented 2 years ago
image image

搜索功能发起的请求 没有参数

正常情况下 html 下引入sdk是正常的...

react18 不行~不知道怎么解决

duolabmeng6 commented 2 years ago

用 amis-react-starter 跑demo是没问题的..用最新的脚手架搭建就有问题...~~

UltramanWeiLai commented 2 years ago

请问这个问题解决了吗? 我现在也是启项目 react18 的初始化 amis-editor 各种报错

UltramanWeiLai commented 2 years ago

请问这个问题解决了吗? 我现在也是启项目 react18 的初始化 amis-editor 各种报错

然后我把 react18 降级成了 react16 就可以了,不过会有 findDOMNode is deprecated in StrictMode. findDOMNode 的 warn 请问这个 warn 怎么处理掉?