npm 链接 React-Redux 失败

Jam*_*nur 6 reactjs react-redux

我正在构建反应组件库。

我需要“npm link”我的库项目才能使用主项目中的react-redux

我这样做就像'npm link ../MainProject/node_modules/react-redux'

但它给了我一个错误:

npm ERR! code 1
npm ERR! path C:\Users\jamal\WorkspaceAmavisca\Cerebrum-Administration\node_modules\react-redux
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c npm run clean && npm run build
npm ERR! > react-redux@7.2.6 clean
npm ERR! > rimraf lib dist es coverage
npm ERR!
npm ERR!
npm ERR! > react-redux@7.2.6 build
npm ERR! > npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min
npm ERR!
npm ERR!
npm ERR! > react-redux@7.2.6 build:commonjs
npm ERR! > cross-env BABEL_ENV=commonjs babel src --out-dir lib
npm ERR! 'cross-env' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

当我将 cross-env 安装为全局时,然后再次尝试 npm 链接。它给我错误:

> npm ERR! Error: spawn babel ENOENT npm ERR! at notFoundError
> (C:\Users\jamal\Apps\nvm\v16.13.1\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
Run Code Online (Sandbox Code Playgroud)

显然,当我执行 npm link 时,react-redux 似乎再次运行其构建脚本但失败了。

有什么帮助吗?

谢谢

  • React-Redux:7.2.1 和 7.2.6
  • 反应:16.14.0
  • ReactDOM:16.14.0
  • Redux:4.0.5 反应
  • 还原:7.2.1
  • 节点16.13.1
  • 国家公共管理:8.1.2

小智 0

而不是使用 npm 链接。如果您使用的是 webpack,请在主项目中使用别名来解决

alias: {
    "react-redux": path.resolve('./node_modules/react-redux'),
    "react": path.resolve('./node_modules/react'),
}
Run Code Online (Sandbox Code Playgroud)