egoist / docute

📚 Effortless documentation, done right.
https://docute.egoist.dev
MIT License
3.8k stars 427 forks source link

TypeError: Cannot destructure property `useConfig` of 'undefined' or 'null'. when "npm run dev" #135

Closed wsd1 closed 6 years ago

wsd1 commented 6 years ago

git clone下来 npm i 就出现这个问题,npm run dev 亦会同样出现。

提示定位在 modules/poi/bin/run.js 233行,我尝试跟踪了代码,但是不是很理解,请作者看看是否是什么小毛病堵着我了。


npm run dev

docute@3.4.9 dev /Users/dy/workshop/docute poi --config build/vue.config.js

Running in development mode Using external Poi config file location: "~/workshop/docute/build/vue.config.js"

TypeError: Cannot destructure property useConfig of 'undefined' or 'null'. at /Users/dy/workshop/docute/node_modules/poi/bin/run.js:233:1 at Generator.next () at onFulfilled (/Users/dy/workshop/docute/node_modules/co/index.js:65:19) at

FAIL Failed to start!

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! docute@3.4.9 dev: poi --config build/vue.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the docute@3.4.9 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/dy/.npm/_logs/2018-01-03T05_19_06_990Z-debug.log


npm_error

环境是 OSx node 8.8.1 npm v5.4.2

兴冲冲的要把玩一番,有种当头凉水的感觉。问题有点奇怪,请看看是否我哪里姿势不对。

egoist commented 6 years ago

use yarn.

wsd1 commented 6 years ago

已经定位: docute/node_modules/poi-load-config/index.js line26

  babel(buildConfigChain) {
    // Check direct and parent directory
    return new Promise(resolve => resolve(babelLoadConfig(this.options.cwd, buildConfigChain) || {}))
  }

babelLoadConfig() 可能返回null,这里会导致后续各种错,所以 加了一个 '||{} '。 亲测该补丁能解决 npm的问题, 请看下是否能带来帮助。

wsd1 commented 6 years ago

另外用 yarn install 也是同样的错误 一样位置的问题。 或者 我的环境配置有些许不一样导致的? 只要我在上面的位置修改一下,错误就会消失 yarn install 也可以欢快的运行到最后~~ 作为poi的作者,请看下我提供的位置 保不齐是个小小的改进。

总之 改后我就可以用了 ,开始玩耍了~~

jahmbo commented 6 years ago

I have the same problem, both with npm and yarn. I've found some solution, maybe workaround

in file poi/bin/run.js in this line, in some cases is return undefined not object and destructuring can't happend const { useConfig, file } = yield loadExternalConfig.babel(buildConfigChain)

changing it to:

      const extConfig = yield loadExternalConfig.babel(buildConfigChain);

      const {
        useConfig = undefined,
        file = undefined
        } = extConfig ? extConfig : {};

resolves the problem

@egoist what do you think?

egoist commented 6 years ago

hmm it should work fine, or try yarn add poi --dev to update poi

jahmbo commented 6 years ago

yeah you are right, with newest poi@9.6.13 version works well