flftfqwxf / mockserver

Mockserver is a mock data tools and switch between mock data and real data,【一个用于前后分离时模拟数据的web系统,并可在直实数据与实际数据中自由切换】
http://mock.chinesefoodrecipes.net
MIT License
338 stars 101 forks source link

使用mockjs中 dataImage报错 #11

Closed highmind closed 7 years ago

highmind commented 7 years ago

{ "array|1-10": [ 1, 2, 3 ], "boolean": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e": "f" }, "url": "@image", "string": "Hello World" }

url为@image 可以,换为 @dataImage则 接口提示

Internal Server Error module.require is not a function

flftfqwxf commented 7 years ago

@highmind 已收到,正在查看

flftfqwxf commented 7 years ago

@highmind 出现此问题是因为 mockjs 本身的问题,在其源代码中有以下说明:

  dataImage: function(size, text) {
            var canvas
            if (typeof document !== 'undefined') {
                canvas = document.createElement('canvas')
            } else {
                /*
                    https://github.com/Automattic/node-canvas
                        npm install canvas --save
                    安装问题:
                    * http://stackoverflow.com/questions/22953206/gulp-issues-with-cario-install-command-not-found-when-trying-to-installing-canva
                    * https://github.com/Automattic/node-canvas/issues/415
                    * https://github.com/Automattic/node-canvas/wiki/_pages

                    PS:node-canvas 的安装过程实在是太繁琐了,所以不放入 package.json 的 dependencies。
                 */
                var Canvas = module.require('canvas')
                canvas = new Canvas()
            }

你可以根据给出的地址尝试安装 canvas包,我自己尝试过,并没有成功。如果你尝试成功,可以在此写下解决办法,谢谢