npm ERR! This package has been marked as private - node.js

I try to publish my angular library on npm.
But i get error
npm ERR! This package has been marked as private. Remove the 'private' field from the package.json to publish it.
But i don't have any private field in my package.json file
My package.json file of my library looks like this:
{
"name": "#myfirst_mylastname/testlib123",
"version": "0.0.1",
"peerDependencies": {
"#angular/common": "^11.1.2",
"#angular/core": "^11.1.2"
},
"dependencies": {
"tslib": "^2.0.0"
},
"description": "Test library",
"author": {"name":"test name"},
"keywords": ["test library"],
}
what i tried
I thought that private is always by default and i added
"private":"false" to my package.json file but i get same error on npm publish.
I googled and i found answers where they say - make private field true or false in the package.json file. I tried that but without success
Why is that ? How can be solved ?

In case this is a problem for anyone else, the error thrown by NPM when publishing a scoped package is misleading.
There may be no "private" field in your package.json file, however scoped packages have their access property set to restricted by default, whereas normal packages are public by default (https://docs.npmjs.com/cli/v8/commands/npm-publish#access).
To be able to publish your scoped package, ensure first that your terminal is in the root of the package - the publish command only affects the directory that you are in.
Then use a flag to set its access property when publishing:
npm publish --access=public
You should also be able to set the default access value for your package using the command
npm access public #myfirst_mylastname/testlib123
which would allow you to publish without specifying the flag. (https://docs.npmjs.com/cli/v8/commands/npm-access#details)

Related

Prevent `npm publish` when ran directly

I am not sure weather it is possible or not.
Is it possible to prevent publish when npm publish ran directly and make it accessible only via scripts.
User must be denied when npm publish is executed directly. i.e. User mush be able to publish via any scripts or npm run <script>
or
is there a way to tell npm only to publish <folder>/ or to look for a tarball when published.
If I mark it private I won't be able to publish at all. My main intention was to prevent accidental publishes.
NPM team gave a simple workaround which is awsome.
package.json
{
"prepublishOnly": "node prepublish.js",
"release": "RELEASE_MODE=true npm publish"
}
prepublish.js
const RELEASE_MODE = !!(process.env.RELEASE_MODE)
if (!RELEASE_MODE) {
console.log('Run `npm run release` to publish the package')
process.exit(1) //which terminates the publish process
}
Mark the package as private:
If you set "private": true in your package.json, then npm will refuse
to publish it.
This is a way to prevent accidental publication of private
repositories. If you would like to ensure that a given package is only
ever published to a specific registry (for example, an internal
registry), then use the publishConfig dictionary described below to
override the registry config param at publish-time.
{
"name": "some",
"version": "1.0.0",
"private": true
}
If you are trying to force something to happen before publishing, leverage the prepublish or prepublishOnly npm-script.
Yes, we can restrict npm to prevent accidental publish by making private: true in package.json
You can have script for publish also
In your package.json
{
"scripts": {
"publish:mypackages": "npm publish folder1/file1.tgz --registry http://custom-registry..."
}
}
Now in cmd: npm run publish:mypackages
It publishes the given tarball to the registry you have given.

How to define dependency in package.json for gitrepository?

In my reactjs project I have a dependency on a module that is in another gitrepo(stash) so I created this in my package.json as a property of dependencies :
"somemodule":{
"name": "somemodule",
"dependencies": {
"private-repo": "https://link_to_the_other_repo"
}
}
This repo contains a minified version and non minified version of the same file. When I run npm install the module does not get installed, there is no error message either. How can I create this dependency?
I have managed to get the dist/minified version of the file from the other repo. How can I refer to this in my package.json?
To add a private git module:
If you have RSA key added to your machine(secure & recommended):
"dependencies": {
"package-name": "git+ssh://git#github.com/project/repo.git"
}
If you want https:
"dependencies": {
"package-name": "git+https://username:password#github.com/project/repo.git"
}
Its not recommended to store username, password in your package.json file, so better add ssh keygen to your machine and use the first one.

npm warn:No README data WARN ,warn: homepage field must start with a protocal

When I follow steps on "Data visualization with D3.js", I meet some problems.
When i create a folder where has a file named package.json which contains:
{
"name": "d3-project-template",
"version": "0.1.0",
"description": "Ready to go d3 data visualization project temple",
"keywords":["data visualization","d3"],
"homepage": "<project home page>",
"author": {"name":"your name","url":"your url"},
"repository":{"type":"git","url":"source repo url"},
"dependencies":{"d3":"3.x"},
"devDependencies": {"uglify-js": "2.x" }
}
and when I get into the folder and type the command npm install:
pri17#pri17-Lenovo-V480:~$ sudo su
[sudo] password for pri17:
root#pri17-Lenovo-V480:/home/pri17# cd /home/pri17/文档/D3-pro
root#pri17-Lenovo-V480:/home/pri17/文档/D3-pro# npm install
npm WARN package.json d3-project-template#0.1.0 No README data
npm WARN package.json d3-project-template#0.1.0 homepage field must start with a protocol.
The parameter to "homepage" needs to actually start with a protocol, e.g. "http". Try replacing what you currently have for the "homepage" with something like this:
"homepage": "http://website.com"

Have you got nightmareJS working properley on c9.io IDE

NightmareJS on c9.io is literally a nightmare.
i cannot get it to work at all i am going to run through the whole process from start to finish.
Step 1
I create a new workspace
Hosted
Node.js
Step 2
Start Editing my new workspace
I open Package.json and add what i need heres my file.
{
"name": "chat-example",
"version": "0.0.0",
"description": "A chat example to showcase how to use `socket.io` with a static `express` server",
"main": "server.js",
"repository": "",
"author": "Mostafa Eweda <mostafa#c9.io>",
"dependencies": {
"async": "~0.2.8",
"express": "~3.2.4",
"socket.io": "~0.9.14",
"phantomjs": "*",
"casperjs": "*",
"nightmarejs": "*",
"utils": "*",
"crypto": "*"
}
}
i then run 'npm install' in the console.
Step 3
this is where it does not work i try all theses diffrent commands to get the examples running and the errors i get.
#stackoverflow:~/828481 $ cd node_modules/nightmarejs/examples/
#stackoverflow:~/828481/node_modules/nightmarejs/examples $ node server.js casper.js
Error: Cannot find module 'crypto'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:7
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:117
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:118
Error: Cannot find module 'casper'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareClient.js:4
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareClient.js:83
TypeError: 'undefined' is not a function (evaluating 'require(phantom.args[3].slice(13)+'nightmareClient.js').Nightmare({
exitOnError: false
})')
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareTest.js:16
I have it working. I also had trouble at first. I tried downloading the prebuilt package, but I can't seem to get that working. I ended up just adding the following to my package.json file and ran npm update and all was well:
"nightmare": "^1.5.0",
"phantomjs": "~1.9.7"
Probably they've updated the npm repo and everything since you've posted this. I bet it was frustrating. I don't have those examples in my install, but I would guess you could run them if you had all of the right pre-req's installed.

Azure Website Deploy Error: install.js: Unable to download msnodesql-0.2.1-v0.10-ia32.msi

Right now, I am trying to set up Node.js website connect to Azure SQL(Not MySQL).
I have created a simple program to get data from Azure mssql database.
On local it works fine.(It retrieves info from Azure MSSQL)
However, when I try to deploy, I get "deployment error".
Here is the gist of error I get.
npm ERR! weird error 1
install.js: Unable to download msnodesql-0.2.1-v0.10-ia32.msi
Failed exitCode=1, command="D:\Program Files (x86)\nodejs\0.10.21\node.exe" "D:\Program Files (x86)\npm\1.3.11\node_modules\npm\bin\npm-cli.js" install --production
An error has occurred during web site deployment.
npm
My package.js is as follows
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.8",
"jade": "*",
"nconf": "~0.6.9"
}
}
Inside, node_modules, there is also mnodesql folder which I downloaded from GitHub[https://github.com/WindowsAzure/node-sqlserver]
I run the following code too.
node-gyp configure
node-gyp build
I would appreciate any advice you can offer.
Thanks.
AFAIK, node-sqlserver needs C++ environment to compile the source code but there's no C++ compiler in Azure Website. What I did is to compile this module on local machine and upload as part of my source code. I covered this scenario at the bottom of my blog http://wblo.gs/dLo.
Hope this helps.

Resources