1

I need to publish package to my local npm (using verdaccio)

the package called: @myorg/database/auth. But npm throw error:

npm ERR! Invalid name: "@myorg/database/auth"

npm ERR! A complete log of this run can be found in:
Error: Command failed: npm publish --tag latest --access public --registry=https://verdaccio-dev.myorg.io

I must using that name. is there an option to ignore or workaround solution?

The name of the package is generated by nrwl/nx. so I can't change that because it will change the entire project structure.

What can I do?

Jon Sud
  • 5,117
  • 3
  • 28
  • 63
  • 1
    I'd say that the problem is the second slash. Names must contain only URL-safe characters although you can define a scoped package in the form of `@scope/package_name` – VirgilioGM Apr 10 '21 at 10:34
  • And what can I do? I have this name because I'm using nx project and the build generate this name for me. I can't change that. – Jon Sud Apr 10 '21 at 10:37
  • I've never used that but I assume there should be a way to set the name you want to the project – VirgilioGM Apr 10 '21 at 10:45

1 Answers1

0

I imagine the issue is that you are generating the library with code like this:

nx generate @nrwl/node:library --name=auth --directory=database

...and you are running (or planning to run) code like this:

import { databaseAuth } from '@myorg/database/auth';

According to their documentation, nx does not select the library name. Rather it is incumbent upon the developer to choose a valid name.

One particularity when generating a library with --publishable is that it requires you to also provide an --importPath. Your import path is the actual scope of your distributable package (e.g.: @myorg/mylib) - which needs to be a valid npm package name.

So, if you ran this:

nx generate @nrwl/node:library -name=auth --directory=database --importPath=@myorg/my-cool-db --publishable

...you should be able to publish your package as @myorg/my-cool-db. But if you specified --importPath=@myorg/database/auth or something like that (with a second slash), I imagine that's the source of the trouble and you'll want to change the importPath value.

Trott
  • 52,114
  • 21
  • 134
  • 179