i5ting/imove

npm install 报错

zhangxh1023 opened this issue · 3 comments

MacOS 11.2.3
Node.js v14.16.0
NPM 6.14.11

User@User imove % npm install

> root@ postinstall /Users/User/own/imove
> lerna init && lerna bootstrap && npm link packages/cli

lerna notice cli v3.22.1
lerna info Updating package.json
lerna info Updating lerna.json
lerna info Creating packages directory
lerna success Initialized Lerna files
lerna notice cli v3.22.1
lerna info Bootstrapping 5 packages
lerna info Symlinking packages and binaries
lerna info lifecycle undefined@undefined~postinstall: undefined@undefined
/Users/User/own/imove/node_modules/npm-lifecycle/index.js:114
  return wd.lastIndexOf(pkg.name) !== wd.length - pkg.name.length
                                                           ^

TypeError: Cannot read property 'length' of undefined
    at _incorrectWorkingDirectory (/Users/User/own/imove/node_modules/npm-lifecycle/index.js:114:60)
    at /Users/User/own/imove/node_modules/npm-lifecycle/index.js:86:44
    at /Users/User/own/imove/node_modules/npm-lifecycle/index.js:218:12
    at callback (/Users/User/own/imove/node_modules/graceful-fs/polyfills.js:299:20)
    at FSReqCallback.oncomplete (fs.js:184:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ postinstall: `lerna init && lerna bootstrap && npm link packages/cli`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ postinstall 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/User/.npm/_logs/2021-03-30T03_56_02_732Z-debug.log

看起来好像是 example 下的 package.json 里面缺少 name 字段。
https://github.com/ykfe/imove/blob/master/example/package.json

是不是应该改成这样,增加一个 name: example 为 package name。

{
  "scripts": {
    "start": "umi dev",
    "build": "umi build",
    "postinstall": "umi generate tmp"
  },
  "dependencies": {
    "@ant-design/pro-layout": "^6.5.0",
    "@imove/core": "^0.3.9",
    "@umijs/preset-react": "1.x",
    "lowdb": "^1.0.0",
    "umi": "^3.3.7"
  },
  "devDependencies": {
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0"
  },
  "name": "example"
}

大概看了一下,应该就是执行 lerna bootstrap 的时候调用 npm-lifecycle 来执行 example 包的postinstall 命令时报错了,因为 example 包缺少 name 字段。

@zhangxh1023 不用执行 lerna bootstrap,如果要跑 example 的话,按以下步骤操作:

$ git clone https://github.com/ykfe/imove.git
$ cd imove/example
$ npm install
$ npm start

不要在根目录 npm install

好的吧,是我看错了。了解了 :)