npmnexus3

npm publish of scoped packages to nexus fails


I have a problem publishing scoped npm-packages to a private nexus-repo.

The name of the package is @spike/core. The error message is:

npm notice Publishing to https://nexus.pitsfs.work/repository/npm-releases/
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://nexus.pitsfs.work/repository/npm-releases/@spike%2fcore
npm ERR! 404
npm ERR! 404  '@spike/core@5.4.3' is not in this registry.

Environment:

It seems to be a problem with the escaped name of @spike/core (escaped to @spike%2fcore). To verify this, I've made the following change to the file c:\Program Files\nodejs\node_modules\npm\node_modules\libnpmpublish\lib\publish.js (which is executed, when npm publish is called):

  ...
  if (!spec.scope && opts.access === 'restricted') {
    throw Object.assign(
      new Error("Can't restrict access to unscoped packages."),
      { code: 'EUNSCOPED' }
    )
  }
  

  // ***************************************************************************  
  // !!! This added line fixed the problem (npm publish worked fine with it) !!!
  // ***************************************************************************  
  spec.escapedName = spec.escapedName.replace("%2f", "/");

  const metadata = buildMetadata(reg, pubManifest, tarballData, opts)

  try {
    return await npmFetch(spec.escapedName, {
      ...opts,
      method: 'PUT',
      body: metadata,
      ignoreBody: true,
    })
  } catch (err) {
  ...

Is there any configuration setting (in npm or nexus) to fix this without patching the file publish.js? I couldn't find anything in the nexus-documentation at https://help.sonatype.com/repomanager2/node-packaged-modules-and-npm-registries)


Solution

  • If you have an webserver in front of your Nexus then you should check it's config. In Apache Webserver it's the option

    AllowEncodedSlashes On
    

    that maybe fix your problem. Maybe the option changed in newer Apache versions - ours was an old one: 2.2.15