gpt4 book ai didi

create-react-app 忽略了 yarn 的注册表配置值

转载 作者:行者123 更新时间:2023-12-01 13:16:34 25 4
gpt4 key购买 nike

我不确定这是否是 create-react-app 的问题或 yarn .

我正在尝试使用 create-react-app .好像用了yarn在引擎盖下获取依赖项,但是 yarn忽略自己的注册表配置设置并尝试直接从 https://registry.yarnpkg.com/ 下载软件包.

这是我尝试使用 create-react-app 时的输出.你可以在最后看到 yarn忽略注册表配置设置:

$ npx create-react-app@2.1.2 my-app --verbose --registry "http://myownregistry:1234/"
npm info it worked if it ends with ok
npm info using npm@6.4.1
npm info using node@v10.13.0
npm timing npm Completed in 153ms
npm info ok
npx: installed 63 in 72.714s

Creating a new React app in C:\work\my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

yarn add v1.13.0
verbose 0.399 Checking for configuration file "C:\\work\\my-app\\.npmrc".
verbose 0.4 Checking for configuration file "C:\\Users\\jbloggs\\.npmrc".
verbose 0.4 Found configuration file "C:\\Users\\jbloggs\\.npmrc".
verbose 0.401 Checking for configuration file "C:\\Program Files\\nodejs\\etc\\npmrc".
verbose 0.401 Checking for configuration file "C:\\work\\my-app\\.npmrc".
verbose 0.402 Checking for configuration file "C:\\work\\.npmrc".
verbose 0.406 Checking for configuration file "C:\\work\\my-app\\.yarnrc".
verbose 0.406 Checking for configuration file "C:\\Users\\jbloggs\\.yarnrc".
verbose 0.406 Found configuration file "C:\\Users\\jbloggs\\.yarnrc".
verbose 0.407 Checking for configuration file "C:\\Program Files\\nodejs\\etc\\yarnrc".
verbose 0.407 Checking for configuration file "C:\\work\\my-app\\.yarnrc".
verbose 0.407 Checking for configuration file "C:\\work\\.yarnrc".
verbose 0.417 current time: 2019-01-21T16:43:06.912Z
[1/4] Resolving packages...
verbose 0.637 Performing "GET" request to "http://myownregistry:1234/react".
verbose 2.827 Request "http://myownregistry:1234/react" finished with status code 200.
verbose 2.837 Performing "GET" request to "http://myownregistry:1234/loose-envify".
verbose 2.839 Performing "GET" request to "http://myownregistry:1234/scheduler".

[... lots of similar lines removed lines removed ...]

verbose 23.218 Request "http://myownregistry:1234/string_decoder" finished with status code 200.
[2/4] Fetching packages...
verbose 23.473 Performing "GET" request to "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz".
verbose 23.483 Performing "GET" request to "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz".
verbose 23.486 Performing "GET" request to "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz".
verbose 23.492 Performing "GET" request to "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz".
verbose 23.514 Performing "GET" request to "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz".
verbose 23.518 Performing "GET" request to "https://registry.yarnpkg.com/@babel/core/-/core-7.1.6.tgz".
verbose 23.52 Performing "GET" request to "https://registry.yarnpkg.com/@svgr/webpack/-/webpack-2.4.1.tgz".
verbose 23.531 Performing "GET" request to "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-9.0.0.tgz".
Missing dependencies in package.json

但是,如果我单独使用 Yarn,它将使用注册表配置值。
$ yarn add object-assign@4.1.1 --verbose
yarn add v1.13.0
verbose 0.375 Checking for configuration file "C:\\work\\.npmrc".
verbose 0.376 Checking for configuration file "C:\\Users\\jbloggs\\.npmrc".
verbose 0.376 Found configuration file "C:\\Users\\jbloggs\\.npmrc".
verbose 0.378 Checking for configuration file "C:\\Program Files\\nodejs\\etc\\npmrc".
verbose 0.379 Checking for configuration file "C:\\work\\.npmrc".
verbose 0.383 Checking for configuration file "C:\\work\\.yarnrc".
verbose 0.383 Checking for configuration file "C:\\Users\\jbloggs\\.yarnrc".
verbose 0.383 Found configuration file "C:\\Users\\jbloggs\\.yarnrc".
verbose 0.384 Checking for configuration file "C:\\Program Files\\nodejs\\etc\\yarnrc".
verbose 0.384 Checking for configuration file "C:\\work\\.yarnrc".
verbose 0.39 current time: 2019-01-21T16:48:15.659Z
info No lockfile found.
[1/4] Resolving packages...
verbose 0.488 Performing "GET" request to "http://myownregistry:1234/object-assign".
verbose 3.892 Request "http://myownregistry:1234/object-assign" finished with status code 200.
[2/4] Fetching packages...
verbose 3.932 Performing "GET" request to "http://myownregistry:1234/object-assign/-/object-assign-4.1.1.tgz".
[3/4] Linking dependencies...
verbose 4.143 Creating directory "C:\\work\\node_modules\\object-assign".
verbose 4.146 Copying "C:\\Users\\jbloggs\\AppData\\Local\\Yarn\\Cache\\v4\\npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863\\node_modules\\object-assign\\index.js" to "C:\\work\\node_modules\\object-assign\\index.js".
verbose 4.147 Copying "C:\\Users\\jbloggs\\AppData\\Local\\Yarn\\Cache\\v4\\npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863\\node_modules\\object-assign\\license" to "C:\\work\\node_modules\\object-assign\\license".
verbose 4.147 Copying "C:\\Users\\jbloggs\\AppData\\Local\\Yarn\\Cache\\v4\\npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863\\node_modules\\object-assign\\package.json" to "C:\\work\\node_modules\\object-assign\\package.json".
verbose 4.147 Copying "C:\\Users\\jbloggs\\AppData\\Local\\Yarn\\Cache\\v4\\npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863\\node_modules\\object-assign\\readme.md" to "C:\\work\\node_modules\\object-assign\\readme.md".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
+- object-assign@4.1.1
info All dependencies
+- object-assign@4.1.1
Done in 3.86s.

我该怎么做才能得到 create-react-app调用 yarn在某种程度上, yarn使用注册表配置值?

最佳答案

我今天遇到了同样的问题并找到了根本原因,有一个 piece of code检查 yarn 配置中的自定义注册表。如果未找到则缓存 yarn.lock安装前将文件(带有指向默认注册表的链接)复制到目标文件夹:

if (yarnUsesDefaultRegistry) {
fs.copySync(
require.resolve('./yarn.lock.cached'),
path.join(root, 'yarn.lock')
);
}

当您从命令行运行相同的安装命令时,与生成的锁定文件没有冲突,并且所有安装都可以使用您的 .npmrc 顺利进行。 .将其捕获为 create-react-app 非常棘手。在安装失败时清除锁定文件:)。
我认为这是 create-react-app问题。简单的解决方法是将自定义注册表显式设置为 yarn:
yarn config set registry http://myownregistry:1234 --global

下一次 create-react-app 运行将选取此属性并跳过缓存锁定文件的复制。

关于create-react-app 忽略了 yarn 的注册表配置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54294592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com