why I am unable to publish my package to npmjs - node.js

I have created an account with npmjs.com also I'm following the how-to-npm tutorial from command line (linux). I'm at the stage where I should publish my test module. But I keep getting error:
You must sign up for private packages : #zentech/node
these are all the error when npm publish
npm ERR! publish Failed PUT 402
npm ERR! Linux 4.10.0-33-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "publish"
npm ERR! node v4.7.2
npm ERR! npm v3.5.2
npm ERR! code E402
npm ERR! You must sign up for private packages : #zentech/node
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/george/node/npm-debug.log
my package.json file
{
"name": "#zentech/node",
"version": "1.0.1",
"main": "index.js",
"preferGlobal": true,
"scripts": {
"test": "node test.js"
},
"author": "",
"license": "ISC",
"description": "",
"repository": "http://github.com/zentech/node"
}
does anyone know why the error? thanks

As suggested in the comments above the way to publish a scoped package i.e.
#scope/my-package
is to use the --access flag when publishing
npm publish --access=public
You do not need to sign up for private packages unless you actually want your package to be private.

Or you can set the public access on package.json:
{
...
"publishConfig": {"access": "public"}
...
}
rather than:
{
...
"publishConfig": {"access": "restricted"}
...
}

You must sign up for private packages: #zentech/node
So you either sign up, or you change the name of your package from #zentech/node to a public name, like zentech-node.

Related

Lerna publish fails "No matching version found" when used in another workspace

I have a project with two workspaces /packages/core and /packages/client and client has core added as a dependency:
{
"name": "core",
"version": "1.0.0-alpha.9",
"dependencies": {},
}
{
"name": "client",
"version": "1.0.0-alpha.9",
"dependencies": {
"core": "^1.0.0-alpha.9",
},
}
If I make a change to both packages, and then try to lerna publish I get an npm error saying the package doesnt exist:
npx lerna publish --no-private
lerna ERR! npm ERR! code ETARGET
lerna ERR! npm ERR! notarget No matching version found for core#^1.0.0-alpha.10.
lerna ERR! npm ERR! notarget In most cases you or one of your dependencies are requesting
lerna ERR! npm ERR! notarget a package version that doesn't exist.
lerna ERR!
Since lerna doesn't clean up on a failed publish, inspecting the package.json's all the files are properly updated to the new version:
{
"name": "core",
"version": "1.0.0-alpha.10",
"dependencies": {},
}
{
"name": "client",
"version": "1.0.0-alpha.10",
"dependencies": {
"core": "^1.0.0-alpha.10",
},
}
How do I properly use a workspace in another workspace without lerna failing to publish?
I realize this is more of an issue with npm than lerna. If I do npm i core -w client after changing the core version manually, it installs fine. Its only when the version is changed and npm i is called that npm cannot seem to figure out that it should still be linking to the local version and not going to the registry.
Switched over to yarn and it works fine.

How to fix 'npm ERR! Exit status 64 ' error in npm

I'm setting up a local server, and I am running my server with npm run json:server but I am getting the following error:
npm ERR! Failed at the jsonserver#1.0.0 json:server script 'json-server --watch db.json'.
Can't figure out how to fix this?
I tried to update npm update -g and it doesn't help.
Also tried npm i -g npm
and install the json server locally using npm i --save-dev json-server
Doesn't help
Lenovo-ideapad-990-95IKB:~/Desktop/jsonserver$ **npm run json:server**
> jsonserver#1.0.0 json:server /home/zack/Desktop/jsonserver
> **json-server --watch db.json**
Could not find an option or flag "-c".
Usage: pub <command> [arguments]
Global options:
-h, --help Print this usage information.
--version Print pub version.
--[no-]trace Print debugging information when an error occurs.
--verbosity Control output verbosity.
[all] Show all output including internal tracing messages.
[error] Show only errors.
[io] Also show IO operations.
[normal] Show errors, warnings, and user messages.
[solver] Show steps during version resolution.
[warning] Show only errors and warnings.
-v, --verbose Shortcut for "--verbosity=all".
Available commands:
cache Work with the system cache.
deps Print package dependencies.
downgrade Downgrade the current package's dependencies to oldest versions.
get Get the current package's dependencies.
global Work with global packages.
help Display help information for pub.
publish Publish the current package to pub.dartlang.org.
run Run an executable from a package.
upgrade Upgrade the current package's dependencies to latest versions.
uploader Manage uploaders for a package on pub.dartlang.org.
version Print pub version.
Run "pub help <command>" for more information about a command.
See http://dartlang.org/tools/pub for detailed documentation.
npm ERR! Linux 4.19.5-041905-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "json:server"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! jsonserver#1.0.0 json:server: `json-server --watch db.json`
npm ERR! **Exit status 64**
npm ERR!
npm ERR! **Failed at the jsonserver#1.0.0 json:server script 'json-server --watch db.json'.**
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the jsonserver package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! json-server --watch db.json
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs jsonserver
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls jsonserver
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/zack/Desktop/jsonserver/npm-debug.log```
Here is package.json:
{
"name": "jsonserver",
"version": "1.0.0",
"description": "REST API Tracker",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.14.2"
}
}
Expected to start server on localhost:3000
Thank you for help!
I think the issue is you're merging the idea of an npm run script with starting a json-server and haven't fully implemented either aspect. Here are the steps I would try, assuming you wish to have a run script to start your json-server:
Rename db.json to package.json since this is actually your package.json file for your node project. You probably created this file when you ran npm init. This file is not the json data that you're mocking for the json-server when you start the server with your custom script command.
Create a new file called db.json and give it the mocked json you wish to use for your json-server. For example, from the documentation:
db.json:
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
Now change your custom run script command to not include special characters. For example, within your package.json change the following:
"scripts": {
"json:server": "json-server --watch db.json"
},
to:
"scripts": {
"start": "json-server --watch db.json"
},
Now start your server with your custom script command: npm run start. At this point there shouldn't be any errors for starting the server.
Now if you go to http://localhost:3000/posts/1, you should get the following json response:
{ "id": 1, "title": "json-server", "author": "typicode" }

Use dependencies from a private GitLab with NPM

I'm trying to install NPM dependencies from a private GitLab instence.
So, I have my repo with basic files
And I added this dependencie in the package.json on my project
"node-demo-package": "https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git"
But, when I run npm install, I receive this error message:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package#https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log
Which I don't understand as there is a package.json as showed in the screenshot.
Here it is
{
"name": "demo-package",
"version": "1.0.0",
"description": "Test pasckage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git#gitlab.fullurl.git"
},
"author": "Arnaud Delante",
"license": "MIT"
}
I already tried switching https by git+https but I get another error
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log
Which is weird because the token is correct.
Would you have any idea?
In package.json try to replace https:// by git+https://
doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Publish npm, and after installation on other PC have error

and then install it on other pc to check. Bu after install package and it depencies i have error when try to start it
pm ERR! Linux 4.10.0-38-generic
npm ERR! argv "/home/pavlo/.nvm/versions/node/v6.11.4/bin/node" "/home/pavlo/.nvm/versions/node/v6.11.4/bin/npm" "start" "storjboard"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! path /home/pavlo/Desktop/test/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/pavlo/Desktop/test/npm-debug.log
Problem it that i have to clone package.json from git , how i can publish correctly with package.json?
Note: command start inside package.json scripts
My json for publish:
{
"name": "name",
"version": "0.0.3",
"description": "Name",
"main": "script.js",
"dependencies": {
"request": "^2.83.0",
},
"devDependencies": {},
"scripts": {
"test": "mocha",
"start": "node node_modules/module/script.js"
},
"repository": {
"type": "git",
"url": "https://github.com/me/module"
},
"keywords": [
"somewords"
],
"author": "me",
"license": "MIT",
"bugs": {
"url": "https://github.com/me/module/issues"
},
"homepage": "https://github.com/me/module#readme"
}
Error (WARN) when installing module on other PC
npm WARN enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.
But in test/node_modules/module/(here there are everything) readme, json and script
If you want to be able to start your module from another directory, you can do it like this:
In your module package.json
{
"name": "module",
"scripts": {
"start": "node script.js"
}
}
from the test directory (as this answer suggest):
npm start --prefix node_modules/module/
Alternately, you can start your module by creating a package.json file in your test directory and adding a script:
{
"name": "test",
"scripts": {
"start": "node node_modules/module/script.js"
}
}
Usally npm packages are placed in node_modules directory because those modules are supposed to be used as dependencies, not directly.
It depends on the purpose of your application, but maybe you might be interested in doing a post-install script or installing it globally.
npm doc for packages installation.

npm - Issue to force npm run jasmine from local node_modules

I installed jasmine npm module as global. Later on, with the purpose of sharing code and make easy for the team to have all dependencies, I installed jasmine locally to the project using --save-dev.
Issue is that it tries to exec from node_modules global one instead of local one.
Package.json
{
"name": "tdd",
"version": "1.0.0",
"description": "testing tdd practices",
"main": "index.js",
"scripts": {
"test": "$(npm bin)/jasmine"
},
"keywords": [
"test",
"tdd",
"jasmine",
"node"
],
"license": "ISC",
"devDependencies": {
"jasmine": "^2.4.1"
}
}
If my tests are passing I get no errors. In case a test does not pass, I get an error pointing to the global node_modules.
Albertos-MBP:TDD albertof$ npm run test
> tdd#1.0.0 test /Users/albertof/Projects/Web/TDD
> jasmine
Started
......FF
Failures:
1) Html Replacement Regex: should replace . in src attributes for <img src="./hello.jpg">
Message:
Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
Stack:
Error: Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
at Object.<anonymous> (/Users/albertof/Projects/Web/TDD/spec/htmlSpec.js:22:62)
8 specs, 1 failures
Finished in 0.015 seconds
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/Users/albertof/npm-global/bin/npm" "run" "test"
npm ERR! node v6.0.0
npm ERR! npm v3.8.8
npm ERR! code ELIFECYCLE
npm ERR! tdd#1.0.0 test: `jasmine`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tdd#1.0.0 test script 'jasmine'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the tdd package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jasmine
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs tdd
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls tdd
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/albertof/Projects/Web/TDD/npm-debug.log
What is the reason to try to execute from the global node_modules installed?
Running npm bin return the local one for the current project /Users/albertof/Projects/Web/TDD/node_modules/.bin
edit your package.json
"scripts": {
"test": "$(npm bin)/jasmine; exit 0"
}

Resources