diff --git a/lib/commands/publish.js b/lib/commands/publish.js index 5bec5f85ec3e0..c59588fefb241 100644 --- a/lib/commands/publish.js +++ b/lib/commands/publish.js @@ -120,7 +120,7 @@ class Publish extends BaseCommand { const isDefaultTag = this.npm.config.isDefault('tag') if (isPreRelease && isDefaultTag) { - throw new Error('You must specify a tag using --tag when publishing a prerelease version') + throw new Error('You must specify a tag using --tag when publishing a prerelease version.') } // If we are not in JSON mode then we show the user the contents of the tarball @@ -161,7 +161,8 @@ class Publish extends BaseCommand { const latestSemverIsGreater = !!latestVersion && semver.gte(latestVersion, manifest.version) if (latestSemverIsGreater && isDefaultTag) { - throw new Error('Cannot publish a lower version without an explicit tag.') + /* eslint-disable-next-line max-len */ + throw new Error(`Cannot implicitly apply the "latest" tag because published version ${latestVersion} is higher than the new version ${manifest.version}. You must specify a tag using --tag.`) } const access = opts.access === null ? 'default' : opts.access diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index aa5a556251f57..10dc9b33deda4 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -885,7 +885,8 @@ t.test('latest dist tag', (t) => { registry.publish(pkg, { noPut: true, packuments }) await t.rejects(async () => { await npm.exec('publish', []) - }, new Error('Cannot publish a lower version without an explicit tag.')) + /* eslint-disable-next-line max-len */ + }, new Error('Cannot implicitly apply the "latest" tag because published version 100.0.0 is higher than the new version 99.0.0. You must specify a tag using --tag.')) }) t.test('ALLOWS publish when latest is HIGHER than publishing version and flag', async t => {