javascript-无法通过npm安装react-dom / test-utils

我在package.json中添加了两个库

  "devDependencies": {
    ...
    "react-dom/test-utils": "*",
    "react-test-renderer/shallow": "*"
  },

react docs所建议,以与React生态系统的版本16兼容.

运行npm install –verbose后,我得到了:

18 verbose node v8.5.0
19 verbose npm  v5.3.0
20 error code EINVALIDPACKAGENAME
21 error Invalid package name "react-dom/test-utils": name can only contain URL-friendly characters
22 verbose exit [ 1, true ]

另外尝试通过cli将其安装为devDependency也会出现此错误:

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/react-dom/test-utils.git
npm ERR! 
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

我如何解决这个问题,以使那些程序包可在代码中引用?

解决方法:

只需添加react-dom作为依赖项:npm install –save-dev react-dom

当您导入react-dom / test-utils时,它的意思是“从react-dom包中的test-utils文件夹/文件中导入”.

上一篇:My Translation Task 4


下一篇:使用 Jest 进行 Vue 单元测试