Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Invalid command openapi, it's not registered #9703

Closed
Longder opened this issue Nov 4, 2022 · 7 comments
Closed

[Bug] Invalid command openapi, it's not registered #9703

Longder opened this issue Nov 4, 2022 · 7 comments

Comments

@Longder
Copy link

Longder commented Nov 4, 2022

添加了umi-openapi插件,在配置中增加:
openAPI: [
{
......
},
],
package.json中增加script:
"openapi": "umi openapi"

执行 npm run openpai 报错:
fatal - AssertionError [ERR_ASSERTION]: Invalid command openapi, it's not registered.
at Service.run (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules@umijs\core\dist\service\service.js:226:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Service.run2 (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\umi\dist\service\service.js:58:12)
at async Object.run (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\umi\dist\cli\cli.js:55:7) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: '=='
}

运行项目报错:
fatal - AssertionError [ERR_ASSERTION]: Invalid config keys: openAPI
at Function.validateConfig (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules@umijs\core\dist\config\config.js:182:31)
at Config.getConfig (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules@umijs\core\dist\config\config.js:60:12)
at Service.resolveConfig (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules@umijs\core\dist\service\service.js:280:97)
at Service.run (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules@umijs\core\dist\service\service.js:237:50)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Service.run2 (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\umi\dist\service\service.js:58:12)

@github-actions
Copy link

github-actions bot commented Nov 4, 2022

由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2022
@fz6m
Copy link
Contributor

fz6m commented Nov 4, 2022

umi4 不再自动加载插件,需要手动添加到配置:

// .umirc.ts

export default {
  plugins: ['...']
}

给一个最小复现。

@Longder
Copy link
Author

Longder commented Nov 4, 2022

umi4 不再自动加载插件,需要手动添加到配置:

// .umirc.ts

export default {
  plugins: ['...']
}

给一个最小复现。

加上了 现在是报:
image

@fz6m
Copy link
Contributor

fz6m commented Nov 4, 2022

这个是旧版插件,不支持 umi4 ,你可能需要这个 https://github.com/umijs/umi-presets-pro/tree/master/packages/max-plugin-openapi

@Longder
Copy link
Author

Longder commented Nov 7, 2022

这个是旧版插件,不支持 umi4 ,你可能需要这个 https://github.com/umijs/umi-presets-pro/tree/master/packages/max-plugin-openapi

更换了max-plugin-openapi,项目本身启动没问题,不过umi openapi生成时候会报错:

Cannot read properties of undefined (reading 'split')
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:158:105
    at Generator.next (<anonymous>)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:4:12)
    at genAllFiles (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:146:44)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:170:13
    at Generator.next (<anonymous>)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:8:71
    at new Promise (<anonymous>)

config.js中openApi配置如下:

export default defineConfig({
  npmClient: 'yarn',
  routes,
  hash: true, 
  history: {
    type: 'hash',
  },
  plugins: ['@umijs/max-plugin-openapi'],
  openAPI: {
    requestLibPath: "import { request } from 'umi'",
    schemaPath: 'http://localhost:8080/api-doc/openapi.json',
    projectName: 'house-paper',
    namespace: 'housePaper',
  },
});

@Longder
Copy link
Author

Longder commented Nov 7, 2022

这个是旧版插件,不支持 umi4 ,你可能需要这个 https://github.com/umijs/umi-presets-pro/tree/master/packages/max-plugin-openapi

更换了max-plugin-openapi,项目本身启动没问题,不过umi openapi生成时候会报错:

Cannot read properties of undefined (reading 'split')
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:158:105
    at Generator.next (<anonymous>)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:4:12)
    at genAllFiles (D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:146:44)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:170:13
    at Generator.next (<anonymous>)
    at D:\Code\IdeaProjects\house-paper\frontend-blockchain\node_modules\@umijs\max-plugin-openapi\dist\index.js:8:71
    at new Promise (<anonymous>)

config.js中openApi配置如下:

export default defineConfig({
  npmClient: 'yarn',
  routes,
  hash: true, 
  history: {
    type: 'hash',
  },
  plugins: ['@umijs/max-plugin-openapi'],
  openAPI: {
    requestLibPath: "import { request } from 'umi'",
    schemaPath: 'http://localhost:8080/api-doc/openapi.json',
    projectName: 'house-paper',
    namespace: 'housePaper',
  },
});

搞定了,需要在package.json中增加name配置~

"name": "project-name"

@zhengtan2003
Copy link

如果出现
api.addBeforeMiddlewares is not a function
就把
"openapi": "umi openapi" 改为 "openapi": "max openapi"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants