sindresorhus / np

A better `npm publish`
MIT License
7.56k stars 299 forks source link

np hangs while publishing #725

Open holdenmatt opened 11 months ago

holdenmatt commented 11 months ago

Description

np was working for me previously, but now when I publish a package the CLI hangs indefinitely on: "Publishing package using npm"

When I check npm, the package is actually published, the CLI just never finished and needs to be aborted. https://status.npmjs.org/ shows no issues.

Is there any workaround or way to see what it's stuck on?

Steps to reproduce

  1. Run np
  2. Make a new patch version
  3. Hangs forever

Expected behavior

The CLI finishes publishing and doesn't hang.

Environment

np - 9.2.0 Node.js - 20.9.0 npm - 10.1.0 OS - macOS 12.3.1

aoifelee commented 11 months ago

I also see it hang, on the "Publishing package using Yarn Berry" step. I just started using np today, so it never worked for me previously. Also, I do not see the published package in npm.

np - 9.2.0 node - 20.10.0 yarn - 4.0.2 OS - macOS 14.1.1

Deemoguse commented 11 months ago

@aoifelee, @holdenmatt I had the same problem and just now I was able to solve it. The problem was that in my package.json file had a publish script that was responsible for publishing the package. It was a mistake to give such a name for this script, because publish is one of the npm hooks that is executed after the package is published to the public.

Make sure that you haven't made the same mistake.

"scripts": {
    "eslint:fix": "eslint **/*.ts --fix --color",
    "build:prod": "rimraf dist & cross-env rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
    "build:test": "rimraf dist & cross-env MODE=test rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
    "test:modules": "jest --verbose --roots test/cases/modules",
    "test:integration": "jest --verbose --roots test/cases/integration",
    "test:perfomance": "jest --verbose --roots test/cases/perfomance",
    "test": "npm run build:test && npm run test:modules && npm run test:integration && npm run test:perfomance && rimraf dist",
-   "publish": "npm run test && npm run build:prod && np --no-tests"
+   "release": "npm run test && npm run build:prod && np --no-tests"
},
PieterT2000 commented 11 months ago

@Deemoguse Thanks, that solved it for me!

ericcarraway commented 6 months ago

For me, the np command would hang indefinitely during the "Publishing package" step. I suspect the problem stemmed from my test script, which was inadvertently running in watch mode while publishing. To resolve this, I modified my npm scripts:

- "test": "vitest",
+ "test": "vitest run",
+ "test:dev": "vitest",

Adjusting the test command to vitest run now executes the tests once and exits, thus preventing the np command from hanging. I've added a test:dev script that retains the original watch mode functionality for development purposes.

This adjustment may help others experiencing similar issues with np hanging due to test scripts not terminating.