I published a package via Github's package manager, and it seemed to work. It appears on the repo's web page and on my profile page. When I run
npm install #franklinharvey/time-remaining#1.0.0
locally it works, but when I try it in a new environment such as Replit or CodeSandbox it does not appear. It also does not appear on npmjs.com
Here are some config files
.npmrc
registry=https://npm.pkg.github.com/franklinharvey
.yarnrc
"#franklinharvey:time-remaining" "https://npm.pkg.github.com"
package.json (partial)
"name": "#franklinharvey/time-remaining",
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"repository": {
"url": "git#github.com:franklinharvey/time-remaining.git"
}
.npmignore
.gitignore
src/
*.log
*.tsbuildinfo
package-lock.json
yarn.lock
coverage
node_modules
Our company also publishes its npm packages via github. Your post gave me an idea, and it fixed the issue on our end.
In a nutshell, I think you need both a fuller .npmrc where you're trying to download the package and not succeeding (containing the registry info as below); as well as to do an npm login if your package is private.
My .npmrc:
#my-company-s-npm-account:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=[GITHUB_AUTH_TOKEN_HERE_WITHOUT_BRACKETS]
registry=https://registry.npmjs.org/
Hope this fixes your issue.
If you can't add an .npmrc or do an npm login where you're trying to install it, and your package is private, I'm not sure how to help.
Related
We have a self-hosted GitLab (15.5.4) and I've configured everything we needed for publishing npm packages.
A CI/CD pipeline that properly creates the entry in the Package Registry.
The problem is that when I pull the package [npm i #scope/lib] (It doesn't change if I cast the auth token in the package.json or I pass through an environment variable as suggested in the documentation) the unwanted result is that the #scope/lib doesn't have the dist/ folder in it!! [node_module/#scope/lib/].
If I browse to the Package Registry and manually download the .tgz file I can see that the dist/ folder is present.
I've played around a bit with the .npmignore and "prepublish" script but I had no success and literally have no glue why this is happening.
Any tips would be very appreciated
To clarify:
The proper way is to tell npm to keep the dist/ folder, bypassing the .gitignore file (instead of defining an .npmignore article here ) is to define a files entry in the package.json :
{
"files": [
"dist",
"build",
...
]
}
Another unproper way to do get the result I needed is to use a postinstall command. But it is clearly an anti-pattern. Given that I am writing a typescript library, that is tested and then compiled by the CI, there's no need to recompile it within the postinstall command. But it could be an hacky solution when needed.
{
"scripts": {
"postinstall": "tsc src/index.ts"
}
}
To sum up, I think it was only an npm cache issue or more probably a server-side cache issue, because I've run npm cache clean --force different times.
Hope this helps.
Given an npm workspace with the following structure
workspace
package.json
packages
package-a
package.json
package-b
package.json
When I run an install command in package-a this will generate a package-lock.json file in the root of the workspace but not in the package.json file itself.
Is there a way to also generate it in the packages?
I don't know if this solves your problem, but you can specifie the folder in which you would install with --prefix
npm install --prefix ./install/here
you can use the lerna tool to manage your workspace and install dependencies in each package. you can generate package-lock.json files in each package in your workspace.
The Original Tool for JavaScript Monorepos. Monorepo means a repository with multiple packages.
lerna.js.org
I hope this answer will show you the right direction.
In most cases, running npm install within that package directory should do the job. But as you said that this is creating a global package-lock.json. This might be because the package you are installing might be specifying the global path using the prefix field.
The "prefix" field, specifies the location where the package's dependencies should be installed.
So one thing you can do is to go to the package.json in package-a and then either remove the prefix field from the package.json file OR set its value as following :
{
"name": "my-package",
"version": "1.0.0",
"prefix": "./",
"dependencies": {
...
}
}
Now when you run npm install it should install the packages locally and make a local 'package-lock.json`.
I have a custom .npmrc file as follows
#foo:registry=https://gitlab.com/api/v4/packages/npm/
// This works and it returns the latest dist tag from the registry as configured in .npmrc
npm view --json #foo/my-package dist-tags
// This fails with a 404
npm access ls-collaborators #foo/my-package
// npm ERR! 404 Not Found - GET https://registry.npmjs.org/-/package/%40foo%2Fmy-package/collaborators?format=cli - Package not found
Some more context:
I am trying to publish an npm package to a private package registry on gitlab using the np module. These commands seem to be executing as part of one of its steps for user authentication.
What am I missing?
Make sure "private": true is in your package.json file. I was running into a similar problem as you, and adding this fixed it for me.
We have a private NPM registry to which we are publishing our packages to, and have a publishConfig section in our projects package.json file which juts contains our registry url which gets picked up by our npm publish commands:
"publishConfig": {
"registry": "xxxxxx"
}
I would like to have this registry url read out from am .nprmc file rather than the package.json.
I have tried doing this, but when using npm publish I get:
400 - Repository with ID='xxx' is Read Only, but action was 'create'!
I figured this may be because I hadnt added my user details to my npmrc, which I have now done, but the problem still remains.
Is it possible for npm publish to use the details from an npmrc specifically?
Just add the following to your .npmrc
registry=YOUR_REGISTRY
I already published a package to NPM, but forgot the README. I updated the package, tried npm publish ./ again, but it says I can't publish on top of a published package.
So, how do I send a README to a published package?
You should increment the version. Like 0.0.0 to 0.0.1.
Just open package.json in your text editor, find "version":"0.0.0" and type in the new value.
After incrementing the version. Like 0.0.0 to 0.0.1 in your package.json file
Create a README.md in the project root directory of your package. after writing up your read me. you can now publish your package by running the npm publish. that should work and should show up your readme on the npm site.