yarn create #scope/package references old version - npm

I've been working on a npm/yarn create script which was once published under
#scopename/originalpackagename
After renaming the package name
#scopename/newpackagename
and removing the old package from npm registry I began getting an error when running
yarn create #scope/newpackagename somename
[1/4] Resolving packages...
verbose 0.174511263 Performing "GET" request to "https://registry.yarnpkg.com/#scope%2fnewpackagename".
verbose 0.385638523 Request "https://registry.yarnpkg.com/#scope%2fnewpackagename" finished with status code 200.
[2/4] Fetching packages...
verbose 0.396535904 Performing "GET" request to "https://registry.yarnpkg.com/#scope/originalpackagename/-/originalpackagename-1.4.0.tgz".
verbose 0.426215495 Error: https://registry.yarnpkg.com/#scope/originalpackagename/-/originalpackagename-1.4.0.tgz: Request failed "404 Not Found"

The issue was only tied to my local machine.
The problem was with the npm manifest located in my home directory.
~/.config/yarn/global/package.json
~/.config/yarn/global/yarn.lock
Which referenced the #scope/oldpackagename.
by removing the following files I was able to fix my problem.
rm ~/.config/yarn/global/package.json
rm ~/.config/yarn/global/yarn.lock

Related

How to remove a dependency in my NPM manifest?

Goal: Create a CRA TypeScript app with Yarn.
I run yarn create react-app my-app --template typescript on my terminal. Then I encounter the ff. error message:
yarn create v1.22.10
[1/4] Resolving packages...
warning create-react-app > tar-pack > tar#2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
[2/4] Fetching packages...
error create-strapi-app#3.6.3: The engine "node" is incompatible with this module. Expected version ">=10.16.0 <=14.x.x". Got "16.14.2"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
And it's super weird and confusing because I'm not trying to create a Strapi project. I check yarn-error.log and I see these lines after the Error Stack Trace:
npm manifest:
{
"dependencies": {
"create-strapi-app": "^3.6.3"
}
}
yarn manifest:
No manifest
So I'm thinking either CRA requires CSA, or somehow my local NPM is configured to always require CSA. I very much doubt the former, so I'm betting it's the latter. (Please correct me if I'm wrong.) Either way, any ideas how I may resolve this?

Can't install a scoped package I published to a npm registry in GCP

I published several npm packages to a private npm registry hosted in GCP and I can see all versions in the registry. Yet I can't download the package since the install command throws an E404.
NPM throws a generic 404 Error when trying to download the page:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://europe-north1-npm.pkg.dev/[Project]/#[scope]/[packagename]/-/#[scope]/[packagename]-0.1.0.tgz
npm ERR! 404
npm ERR! 404 '#[scope]/[packagename]#https://europe-north1-npm.pkg.dev/[Project]/#[scope]/[packagename]/-/#[scope]/[packagename]-0.1.0.tgz' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
Opening the url that is tring to resolve returns this error:
{"error":"Permission \"artifactregistry.repositories.downloadArtifacts\" denied on resource \"projects/[Project]/locations/europe-north1/repositories/#[scope]\" (or it may not exist)"}
{"error":"Unmatched scope name: \"\" != \"#[scope]\""}
Additonally, I checked and my account does in fact have to downloadArtifacts role.
I can't figure out why it's unable to resolve the URL since with the same config I'm able to both publish and even run npm view the package.
I've tried creating brand new packages, specifying a version, resetting the auth token and yet for some reason I'm still unable to download packages.
If it helps, my current .npmrc file looks like this:
registry:https://registry.npmjs.org/=true
#[scope]:registry=https://europe-north1-npm.pkg.dev/[project]/[repo name]/
//europe-north1-npm.pkg.dev/[project]/[repo name]/:_authToken=[gcp auth token]
//europe-north1-npm.pkg.dev/[project]/[repo name]/:always-auth=true
//registry.npmjs.org/:_authToken=[npm auth token]
Turns out this was not a GCP specific issue, but a Yarn Berry issue when publishing to GCP.
The tarballURL that is being generated uses a truncated registry URL which is why i was getting a 404 when trying to install the package.
A fix for this was proposed here.
https://github.com/yarnpkg/berry/pull/3513
I had an error similar to this one.
I did the entire repository creation process and created a new project to test the package.
When I tried npm install my-package I got a 404 error.
After some tests I discovered that I need the .npmrc file also in the project that will consume the package. It may seem kind of obvious to some people but I didn't know.
Add the returned configuration settings to the .npmrc configuration file in your Node.js projects. This file is usually in the same directory as package.json.
Make sure that you include these settings in Node.js projects for packages that you publish as well as projects that will install dependencies from your npm repository.
Set up authentication for npm

How do I install react and react-redux onto my project?

Good afternoon,
I am trying to install react and react-redux onto my project, but I keep getting errors that I don't understand.
$ npx create-react-app learn-redux
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Phelps\AppData\Roaming\npm-cache\_npx\13464" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Taylor Phelps\AppData\Roaming\npm-cache\_logs\2020-02-08T20_44_17_568Z-debug.log
Install for [ 'create-react-app#latest' ] failed with code 1
Could not install from "Phelps\AppData\Roaming\npm-cache\_npx\13464" as it does not contain a package.json file.
I am reading the error, but the problem is...that folder does not exist on my computer and I've checked in the terminal for npm and npx and both are installed on my computer. Does anyone have any ideas on why this may be happening and how to fix it?
Thank you.
According to this Github issue npx has trouble running on Windows if the user has a space in their name and from the error message I'd guess that is the case here. One of the suggested fixes is to set your npm-cache path to a folder without a space in it:
npm config set cache C:\tmp\nodejs\npm-cache --global
Then try running your command again.
Install the project in another directory except C partition :
npx create-react-app learnredux
Then :
npm i react-redux --save
This should work.
The problem is the npm cache by the path of the error. Try running:
npm cache verify
Verify the contents of the cache folder, garbage collecting any
unneeded data, and verifying the integrity of the cache index and all
cached data.
(from https://docs.npmjs.com/cli-commands/cache.html)

Does "npm install" look for packages in local cache first?

I was trying to figure out how local cache is fitted in npm install flow. I did the following:
npm cache clear --force
npm cache rd
npm install react#16.10.1
I disconnected from the internet
I removed the node_modules directory
npm install react#16.10.1
The package got installed and a package-lock.json was created successfully; however the following warning in the console made me confused:
Using stale data from https://registry.npmjs.org/ because the host is inaccessible -- are you offline?
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
...
...
Why did npm try to connect to the registry at all while the package does exist in the local cache? and
What was npm trying to get from the registry? Did it try to download the whole package or it just wanted to check some metadata like hash or so?

create-react-app is ignoring yarn's registry config value

I am not sure if this is a problem with create-react-app or yarn.
I am trying to use create-react-app. It seems to use yarn under the hood to fetch dependencies, but yarn is ignoring its own registry config setting and tries to download packages directly from https://registry.yarnpkg.com/.
This is the output when I try to use create-react-app. You can see at the end that yarn ignores the registry config setting:
$ 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
However, if I use Yarn on its own, it will use the registry config value.
$ 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.
What can I do to get create-react-app to invoke yarn in a way that yarn uses the registry config value?
I got same issue today and found the root cause, there is a piece of code checking for custom registry in yarn config. If not found then cached yarn.lock file (with links to default registry inside) is copied to target folder before install:
if (yarnUsesDefaultRegistry) {
fs.copySync(
require.resolve('./yarn.lock.cached'),
path.join(root, 'yarn.lock')
);
}
When you run the same install command from command line, then no conflict with generated lock file and all installs smoothly using your .npmrc. It was quite tricky to catch this as create-react-app clears lock file on failed install :).
I would consider this as create-react-app issue. Simple workaround is to set custom registry to yarn explicitly:
yarn config set registry http://myownregistry:1234 --global
Next create-react-app run will pick up this property and skip copying of cached lock file.
As far as I see, initial yarn installation of create-react-app doesn't accept/honor custom registry settings(Source code). But it does honor --verbose option(Source code).
You can create issue in official repo for custom registry support. There are some issues around this already(like this one). but, looks like this is a good to have feature.