imageslr / weapp-library

“在线借书平台”微信小程序:连接读者与图书馆的借书平台、读者的图书资料库与书单系统。30+ 页面,多个可复用组件,微信小程序开发入门。提供本地 mock server 解决方案。
https://imageslr.github.io/weapp-library/
Apache License 2.0
1.06k stars 262 forks source link

TypeError: router[method] is not a function #9

Closed 1097872822 closed 3 years ago

1097872822 commented 3 years ago

D:\桌面的东西\预约功能\weapp-library\simplest-mock-server>gulp mock [11:26:04] Using gulpfile D:\桌面的东西\小程序\weapp-library\simplest-mock-server\gulpfile.js [11:26:04] Starting 'mock'... [11:26:04] Finished 'mock' after 93 ms [11:26:04] [nodemon] 2.0.7 [11:26:04] [nodemon] to restart at any time, enter rs [11:26:04] [nodemon] watching path(s): example*\ server.js router.js [11:26:04] [nodemon] watching extensions: js,json [11:26:04] [nodemon] starting node ./server.js --dir example --port 3000 [INFO] Reading mock template file: D:\桌面的东西\小程序\weapp-library\simplest-mock-server\example\DELETE\users{id}.json [INFO] Reading mock template file: D:\桌面的东西\小程序\weapp-library\simplest-mock-server\example\GET\api\v1\users{id}.json [INFO] Reading mock template file: D:\桌面的东西\小程序\weapp-library\simplest-mock-server\example\GET\echo.json [INFO] Reading mock template file: D:\桌面的东西\小程序\weapp-library\simplest-mock-server\example\GET\users.json [INFO] Reading mock template file: D:\桌面的东西\小程序\weapp-library\simplest-mock-server\example\POST\users.json D:\桌面的东西\小程序\weapp-library\simplest-mock-server\router.js:69 routermethod; ^ TypeError: router[method] is not a function at D:\桌面的东西\小程序\weapp-library\simplest-mock-server\router.js:69:17 at Array.forEach () at Object. (D:\桌面的东西\小程序\weapp-library\simplest-mock-server\router.js:50:8) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Module.require (internal/modules/cjs/loader.js:1019:19) at require (internal/modules/cjs/helpers.js:77:18) at Object. (D:\桌面的东西\小程序\weapp-library\simplest-mock-server\server.js:12:16) application has crashed! [11:26:04] [nodemon] app crashed - waiting for file changes before starting...

请问博主我在使用gulp mock遇到router.js中的router[method] is not a function的问题,我找过很多相关解决办法但依旧未能解决,请问是否是我node版本 与 gulp版本问题所导致的呢?若您有空看到并给出一些建议,万分感谢~【node isv12.16.3 & gulp is 3.9.1,并且已经npm install】

imageslr commented 3 years ago

hi,请再拉取最新代码运行一下,会打印出更有用的错误信息。这里可能是文件夹名称的问题。

1097872822 commented 3 years ago

之前的问题都解决了,包含中文的文件名也移至全英文文件夹,但gulp mock启动仍然出现ruter[methor] is not a function: n*【info】... [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\delete\api\v1\booklists{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\delete\api\v1\orders{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\delete\api\v1\reviews{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\booklists\recommend{phone}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\booklists\search.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\booklists\users{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\booklists{id}\books.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\booklists{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\authors{author}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\classifications{class}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\isbn{isbn}\collections.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\isbn{isbn}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\ranking.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\recommend{phone}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\search\advanced.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\search.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books\tags{tag}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books{id}\collections.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books{id}\reviews.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\books{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\classifications{id}\sons.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\codes\check.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\images.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\libraries{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\orders\return.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\orders\users{phone}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\orders{id}\take.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\orders{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\reviews{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\users{phone}\reviews.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\users{phone}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\get\api\v1\users.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\booklists{id}\favorite.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\booklists{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\booklists.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\books{id}\reviews.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\codes.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\orders{id}\cancel.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\orders{id}\renew.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\orders{id}.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\orders.jso url: n error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d:\booking\weapp-library\weapp-library\simplest-mock-server\example\post\api\v1\users{phone}.jso url: n error: TypeError: router[method] is not a function open mock server at localhost:3000

imageslr commented 3 years ago

@1097872822 额..我知道了,是因为我在代码里解析路径时使用了 /,而 windows 下都是 \。我想想咋解决。

imageslr commented 3 years ago

更新了下代码。我这边没有 windows 环境可以测试,需要你拉下来跑一下 @1097872822

1097872822 commented 3 years ago

@imageslr 好的,感谢

1097872822 commented 3 years ago

问题依旧...TypeError: router[method] is not a function

imageslr commented 3 years ago

再贴下完整日志吧。

如果只是想开发预览,可以参考 README 的“云开发”部分,把 simplest-mock-server 上传到云托管。这一步也很简单。

1097872822 commented 3 years ago

[INFO] Reading mock template file: D:\booking\weapp-library\weapp-library\simplest-mock-server\example\POST\api\v1\users{phone}.json [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/DELETE/api/v1/booklists/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/DELETE/api/v1/orders/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/DELETE/api/v1/reviews/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/booklists/recommend/:phone error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/booklists/search error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/booklists/users/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/booklists/:id/books error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/booklists/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/authors/:author error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/classifications/:class error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/isbn/:isbn/collections error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/isbn/:isbn error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/ranking error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/recommend/:phone error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/search/advanced error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/search error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/tags/:tag error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/:id/collections error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/:id/reviews error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/books/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/classifications/:id/sons error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/codes/check error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/images error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/libraries/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/orders/return error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/orders/users/:phone error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/orders/:id/take error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/orders/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/reviews/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/users/:phone/reviews error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/users/:phone error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/GET/api/v1/users error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/booklists/:id/favorite error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/booklists/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/booklists error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/books/:id/reviews error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/codes error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/orders/:id/cancel error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/orders/:id/renew error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/orders/:id error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/orders error: TypeError: router[method] is not a function [Error] Add mock api failed, method: d: url: /booking/weapp-library/weapp-library/simplest-mock-server/example/POST/api/v1/users/:phone error: TypeError: router[method] is not a function open mock server at localhost:3000 GET /api/v1 404 2.080 ms - 145 GET /api/v1 404 0.309 ms - 145 以上是拉取新的router.js代码并更新启动glup mock后的输出结果

另外云托管部分我已按照文档做了,并且改了request.js文件响应的内容

imageslr commented 3 years ago

好。我大概知道问题是啥了,我之后在 windows 测试吧。可以先用云托管调试

1097872822 commented 3 years ago

好 再次感谢负责的开发者 哈哈~

imageslr commented 3 years ago

新代码我在 windows 测试已经没有问题了,可以再试试。