yapi 关于二次开发编译部署的一些心得

hk8txs48  于 5个月前  发布在  其他
关注(0)|答案(6)|浏览(61)

感谢官方开源Yapi,然后基于最新版本,做了2次开发,总结一些开发过程中遇到的坑,给其他兄弟参考

YAPI是在mac下开发的,大家尽量用mac,这样报错少一些,我在win10下会遇到各种奇怪的问题,包括组件包安装失败,编译报错,不识别的linux命令等,如果遇到了就单独一个个解决,这个和环境有关系,每个人遇到的可能都不一样,我在mac和win下都进行了测试,总体mac会顺利很多

由于服务器环境不同,node和YApi的组件版本都比较低,服务器编译容易出各种错误,官方docker部署不会编译前端代码,默认复制static/prd下面已经编译好的js代码

关于docker部署:

  • 先自行在服务器提前配置好环境(安装node,ykit和webpack等相关组件,可能需要全局安装,具体看服务器设置,需要有sudo权限,全部安装完毕后,在服务器手动执行npm run build-client 看能否正确编译)如果能编译正确,生成编译文件,那么恭喜你,可以用方案二,如果有各种报错又懒得解决,就用方案一,我这边服务器是unbantu,某些包总是安装失败,我也没有最高权限,就用方案一了

  • 方案一:每次docker build之前先手动在本地npm run build-client编译,生成最终文件上传服务器,这样docker 就直接复制文件不走编译了

  • 方案二:修改dockerfile里增加编译代码 npm run build-client 即可,这样每次docker build都会重新编译文件,编译时间根据硬件配置不同时间不同

官方1.12.0默认关闭了全局Mock脚本,这个功能慎用,vm2 沙箱组件执行完会有无法退出linux进程的问题,导致请求一次创建一个进程,最终几千上万个进程把内存耗光,这个应该是vm2的问题,不是yapi的问题,暂时没有好的解决办法,所以官方禁用了事 。如果有修复麻烦告知谢谢,这个已经有人在vm2的github提issue了,但是官方没有更新

开发环境配置(基于MAC)
node版本: node v10.24.1 (npm v6.14.12),node版本不要高于12,否则部分组件版本过低会报错

antd版本锁定3.20.0,再高会有样式错误,这个已经经过测试了

打包采用ykit,需要独立全局安装

npm install ykit -g
如果有报错,可以使用
npm install ykit -g --unsafe-perm=true --allow-root

生产模式打包
npm run build-client
或者直接
NODE_ENV=production ykit pack -m
如果提示某些 module not found,独立安装即可

打包编译问题参考 https://juejin.cn/post/7246596616694317114 感谢文章作者,这里面解决了大部分的编译警告问题

数据库没有版本要求,我自己装的最新版本mongodb(当时,2023年中),但是mongo的更新非常频繁,新版本会废弃一些旧版本的指令,所以不要安装现在的最新版本,如果遇到运行警告或者错误

  1. 自己修改yapi中操作数据库的指令,适应新版本
  2. 降低mongo的版本,我当时装的应该是7.0.2,会提示有几个指令将废弃,不想改就再降低版本

部署命令

编译容器
docker build -t yapi .

启动容器,注意mongodb_ip 这里是ip地址,不加端口,端口在config文件默认配置27017

docker run -p 3000:3000 --name yapi_web -e YAPI_ADMIN_ACCOUNT=admin@admin.com \
-e YAPI_DB_SERVER_NAME={mongodb_ip} -e YAPI_DB_USER={mongodb_user} -e YAPI_DB_PASS={mongodb_pass} yapi
wi3ka0sx

wi3ka0sx1#

我深受数据库版本影响,我用的7.0.5 😭:

log: mongodb load success...
(node:253592) UnhandledPromiseRejectionWarning: MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal
jgovgodb

jgovgodb2#

我深受数据库版本影响,我用的7.0.5 😭:

log: mongodb load success...
(node:253592) UnhandledPromiseRejectionWarning: MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal

降一下数据库版本,新版本废弃了一些指令,加了一些新指令,我这个二次开发是去年搞得,当时的mongo用的7.0.2,要是还不行就再降低一下,我也遇到了查询指令废弃的警告,我自己手动改了部分yapi的数据库操作指令来适应mongo新版本

k97glaaz

k97glaaz3#

我深受数据库版本影响,我用的7.0.5 😭:

log: mongodb load success...
(node:253592) UnhandledPromiseRejectionWarning: MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal

降一下数据库版本,新版本废弃了一些指令,加了一些新指令,我这个二次开发是去年搞得,当时的mongo用的7.0.2,要是还不行就再降低一下,我也遇到了查询指令废弃的警告,我自己手动改了部分yapi的数据库操作指令来适应mongo新版本

我是做迁移,原来的yapi版本太低了,安装了最新的数据库版本就有影响了。我升级到最新版的yapi后就可以了,其实好在官方没有调整数据库结构,原来的数据还能在最新的yapi版本中使用,感谢yapi!

hpcdzsge

hpcdzsge4#

麻烦问下,yapi的插件
export-docx-data 数据导出docx文档
interface-oauth-token 定时自动获取鉴权token的插件
import-swagger-customize 导入指定swagger接口
这些对yapi的版本有要求吗?

我使用如下的node版本呢,yapi 1.12.0和1.9.2都尝试安装插件,ykit都编译不过,文档太不友好了,什么版本关系都不写,谢谢
[root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# node -v
v10.24.1
[root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# npm -v
6.14.12

[root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# NODE_ENV=production ykit pack -m
[error] ./~/swagger-client/lib/index.js
Module parse failed: /opt/my-yapi/vendors/node_modules/swagger-client/lib/index.js Unexpected token (106:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (106:6)
    at Parser.pp$4.raise (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp$3.parseIdent (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2189:12)
    at Parser.pp$3.parsePropertyName (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2052:101)
    at Parser.pp$3.parseObj (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1988:14)
    at Parser.pp$3.parseExprAtom (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1805:19)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1597:21)
    at Parser.pp$3.parseExprList (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2165:22)
    at Parser.pp$3.parseSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1741:35)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1718:17)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
 @ ./~/swagger-client/lib/commonjs.js 6:4-25

[error] ../config.json
Module build failed: SyntaxError: Unexpected token m in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.module.exports (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/json-loader/index.js:4:49)
 @ ./server/yapi.js 12:13-41

[error] ./~/fs-extra/lib/empty/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/fs-extra/lib/empty
 @ ./~/fs-extra/lib/empty/index.js 4:11-24

[error] ./~/nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Cannot resolve module 'child_process' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/sendmail-transport
 @ ./~/nodemailer/lib/sendmail-transport/index.js 3:14-38

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 13:12-26

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'dns' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 14:12-26

[error] ./~/nodemailer/lib/shared/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/shared
 @ ./~/nodemailer/lib/shared/index.js 5:11-24

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 7:12-26

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 8:12-26

[error] ./~/nodemailer/lib/dkim/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/dkim
 @ ./~/nodemailer/lib/dkim/index.js 10:11-24

[error] ./~/graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/graceful-fs
 @ ./~/graceful-fs/graceful-fs.js 1:9-22

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 5:12-26

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 6:12-26

[error] ./~/jsonfile/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/jsonfile
 @ ./~/jsonfile/index.js 5:8-21

[error] ./~/nodemailer/lib/mime-node/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mime-node
 @ ./~/nodemailer/lib/mime-node/index.js 7:11-24

[error] index@81fd9c14bf4309f57a35.js from UglifyJs
SyntaxError: Name expected [../~/swagger-client/lib/commonjs.js:4,0]
wxclj1h5

wxclj1h55#

麻烦问下,yapi的插件 export-docx-data 数据导出docx文档 interface-oauth-token 定时自动获取鉴权token的插件 import-swagger-customize 导入指定swagger接口 这些对yapi的版本有要求吗?

我使用如下的node版本呢,yapi 1.12.0和1.9.2都尝试安装插件,ykit都编译不过,文档太不友好了,什么版本关系都不写,谢谢 [root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# node -v v10.24.1 [root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# npm -v 6.14.12

[root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# NODE_ENV=production ykit pack -m
[error] ./~/swagger-client/lib/index.js
Module parse failed: /opt/my-yapi/vendors/node_modules/swagger-client/lib/index.js Unexpected token (106:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (106:6)
    at Parser.pp$4.raise (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp$3.parseIdent (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2189:12)
    at Parser.pp$3.parsePropertyName (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2052:101)
    at Parser.pp$3.parseObj (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1988:14)
    at Parser.pp$3.parseExprAtom (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1805:19)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1597:21)
    at Parser.pp$3.parseExprList (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2165:22)
    at Parser.pp$3.parseSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1741:35)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1718:17)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
 @ ./~/swagger-client/lib/commonjs.js 6:4-25

[error] ../config.json
Module build failed: SyntaxError: Unexpected token m in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.module.exports (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/json-loader/index.js:4:49)
 @ ./server/yapi.js 12:13-41

[error] ./~/fs-extra/lib/empty/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/fs-extra/lib/empty
 @ ./~/fs-extra/lib/empty/index.js 4:11-24

[error] ./~/nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Cannot resolve module 'child_process' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/sendmail-transport
 @ ./~/nodemailer/lib/sendmail-transport/index.js 3:14-38

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 13:12-26

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'dns' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 14:12-26

[error] ./~/nodemailer/lib/shared/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/shared
 @ ./~/nodemailer/lib/shared/index.js 5:11-24

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 7:12-26

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 8:12-26

[error] ./~/nodemailer/lib/dkim/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/dkim
 @ ./~/nodemailer/lib/dkim/index.js 10:11-24

[error] ./~/graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/graceful-fs
 @ ./~/graceful-fs/graceful-fs.js 1:9-22

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 5:12-26

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 6:12-26

[error] ./~/jsonfile/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/jsonfile
 @ ./~/jsonfile/index.js 5:8-21

[error] ./~/nodemailer/lib/mime-node/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mime-node
 @ ./~/nodemailer/lib/mime-node/index.js 7:11-24

[error] index@81fd9c14bf4309f57a35.js from UglifyJs
SyntaxError: Name expected [../~/swagger-client/lib/commonjs.js:4,0]

我没有使用这些插件,所以不太了解具体问题,通常插件开发必须对应yapi的版本号,因为yapi的任何升级都可能造成插件失效,这个具体需要问插件作者了

index.js Unexpected token (106:6)
Module build failed: SyntaxError: Unexpected token m in JSON at position 0

这种更多是文件解析错误(如果文件本身没有问题的话),查一下babel设置
可以参考这个issue #1865

Cannot resolve module 'fs'
Error: Cannot resolve module 'net'
这些类似问题可以参考下面文章解决
https://juejin.cn/post/7246596616694317114

g2ieeal7

g2ieeal76#

麻烦问下,yapi的插件 export-docx-data 数据导出docx文档 interface-oauth-token 定时自动获取鉴权token的插件 import-swagger-customize 导入指定swagger接口 这些对yapi的版本有要求吗?
我使用如下的node版本呢,yapi 1.12.0和1.9.2都尝试安装插件,ykit都编译不过,文档太不友好了,什么版本关系都不写,谢谢 [root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# node -v v10.24.1 [root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# npm -v 6.14.12

[root@iZ2zecfhh6x8qvhg4it0oaZ vendors]# NODE_ENV=production ykit pack -m
[error] ./~/swagger-client/lib/index.js
Module parse failed: /opt/my-yapi/vendors/node_modules/swagger-client/lib/index.js Unexpected token (106:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (106:6)
    at Parser.pp$4.raise (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp$3.parseIdent (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2189:12)
    at Parser.pp$3.parsePropertyName (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2052:101)
    at Parser.pp$3.parseObj (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1988:14)
    at Parser.pp$3.parseExprAtom (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1805:19)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1597:21)
    at Parser.pp$3.parseExprList (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:2165:22)
    at Parser.pp$3.parseSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1741:35)
    at Parser.pp$3.parseExprSubscripts (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1718:17)
    at Parser.pp$3.parseMaybeUnary (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
 @ ./~/swagger-client/lib/commonjs.js 6:4-25

[error] ../config.json
Module build failed: SyntaxError: Unexpected token m in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.module.exports (/root/.nvm/versions/node/v10.24.1/lib/node_modules/ykit/node_modules/json-loader/index.js:4:49)
 @ ./server/yapi.js 12:13-41

[error] ./~/fs-extra/lib/empty/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/fs-extra/lib/empty
 @ ./~/fs-extra/lib/empty/index.js 4:11-24

[error] ./~/nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Cannot resolve module 'child_process' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/sendmail-transport
 @ ./~/nodemailer/lib/sendmail-transport/index.js 3:14-38

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 13:12-26

[error] ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'dns' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 14:12-26

[error] ./~/nodemailer/lib/shared/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/shared
 @ ./~/nodemailer/lib/shared/index.js 5:11-24

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 7:12-26

[error] ./~/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/http-proxy-client.js 8:12-26

[error] ./~/nodemailer/lib/dkim/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/dkim
 @ ./~/nodemailer/lib/dkim/index.js 10:11-24

[error] ./~/graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/graceful-fs
 @ ./~/graceful-fs/graceful-fs.js 1:9-22

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'net' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 5:12-26

[error] ./~/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'tls' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/smtp-connection
 @ ./~/nodemailer/lib/smtp-connection/index.js 6:12-26

[error] ./~/jsonfile/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/jsonfile
 @ ./~/jsonfile/index.js 5:8-21

[error] ./~/nodemailer/lib/mime-node/index.js
Module not found: Error: Cannot resolve module 'fs' in /opt/my-yapi/vendors/node_modules/nodemailer/lib/mime-node
 @ ./~/nodemailer/lib/mime-node/index.js 7:11-24

[error] index@81fd9c14bf4309f57a35.js from UglifyJs
SyntaxError: Name expected [../~/swagger-client/lib/commonjs.js:4,0]

我没有使用这些插件,所以不太了解具体问题,通常插件开发必须对应yapi的版本号,因为yapi的任何升级都可能造成插件失效,这个具体需要问插件作者了

index.js Unexpected token (106:6) Module build failed: SyntaxError: Unexpected token m in JSON at position 0

这种更多是文件解析错误(如果文件本身没有问题的话),查一下babel设置 可以参考这个issue #1865

Cannot resolve module 'fs' Error: Cannot resolve module 'net' 这些类似问题可以参考下面文章解决 https://juejin.cn/post/7246596616694317114

感谢,感谢,编译通过了

相关问题