异常修改, 抛异常
C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dva-cli\bin\dva-generate create routeComponent src/routes/Users.js,src/routes/Users.css TypeError: root.findRouters(...).getRouterInfo is not a function at transform (C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dva-cli\nod e_modules\dva-ast\lib\transform.js:42:32) at exports.default (C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dva-c li\node_modules\dva-ast\lib\api\index.js:46:36) at C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dva-cli\lib\generate.j s:92:27 at generate (C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dva-cli\lib\ generate.js:108:11) at Object.<anonymous> (C:\Users\thinkpad\AppData\Roaming\npm\node_modules\dv a-cli\bin\dva-generate:11:27) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)
解决方法如下:
@H_301_15@
wenriscommented14 days ago•edited
这个 bug 让我怀疑自己人生。问题的根源是,我们安装的dva-cli>dva-ast>jscodeshift的版本不对!
dva-ast中使用了下面的代码:
Collection
是jscodeshift库提供的,dva-ast的package.json
指定"jscodeshift": "^0.3.28"
,但jscodeshift最新版本是0.3.32
,这里 Bug 就出现了。虽然我发现了问题根源,但dva-ast和jscodeshift这两个库的源代码看得我云里雾里,望而生畏,杀虫的工作还是等高手吧。
我目前的解决方法是,将全局安装的jscodeshift回滚至
0.3.28
,初入江湖的我,人生还可以继续么?Roll your global packagejscodeshiftback to
v0.3.28
.