使用npx运行create-react-app时,意外地通过yarn安装了create-react-app,

e3bfsja2  于 20天前  发布在  React
关注(0)|答案(2)|浏览(15)

描述bug

通过使用NPX,它暗示用户想要使用NPM,然而create-react-app仍然强制将zucc添加到用户的yarn中。

你尝试恢复依赖了吗?

是的。这确实解决了问题。但那不是问题所在。问题在于,通过使用NPX,它暗示我想要使用NPM。如果我使用的是yarn,我会使用yarn create react-app

你在用户指南中搜索了哪些术语?

我搜索了类似这样的问题,但找不到任何相关信息。

环境

current version of create-react-app: 4.0.3
  running from /home/alice/.npm/_npx/9475/lib/node_modules/create-react-app

  System:
    OS: Linux 4.4 Ubuntu 18.04.4 LTS (Bionic Beaver)
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    react: ^17.0.1 => 17.0.1
    react-dom: ^17.0.1 => 17.0.1
    react-scripts: 4.0.2 => 4.0.2
  npmGlobalPackages:
    create-react-app: Not Found

重现步骤

npx create-react-app thisbug
cd thisbug
npm i express --save
find node_modules/.bin -type l ! -exec test -e {} \; -print # detects broken symlinks. output: node_modules/.bin/node-which

预期行为

我希望它使用NPM进行安装。我知道有一个--use-npm标志,但那已经超出了这个问题的范围。
find命令没有返回输出,意味着没有损坏的符号链接

实际行为

node_modules/.bin/node-which是一个损坏的符号链接。
我明白这是一个与npm和yarn的兼容性问题,特别是在ubuntu上(在windows上不是问题),但是,与其与NPM争论,我认为更好的做法是责怪create-react-app,因为yarnpkg不期望在这种情况下运行,因为npx是由npm提供的。
注意这张截图是在运行npx create-react-app thisbug && cd thisbug然后npm i express --save之后拍摄的。

(写下发生了什么。请添加屏幕截图!)

可复现示例

npx create-react-app my-app

# installing via yarnpkg
bweufnob

bweufnob1#

请检查您的yarn全局添加列表

% yarn global list
info "create-react-app@4.0.3" has binaries:
   - create-react-app

如果yarn有CRA二进制文件,您可以将其删除

% yarn global remove create-react-app

然后执行npx

% npx create-react-app my-app

它是如何执行的?

jc3wubiy

jc3wubiy2#

我认为你误解了。这不是一个配置问题。我从来没有真正使用过yarn...就像从未有过一样。
当然,这是输出结果。

❯  yarn global list
yarn global v1.22.4
Done in 0.06s.
❯ yarn global remove create-react-app
yarn global v1.22.4
[1/2] Removing module create-react-app...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

相关问题