-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm publish fails / npm publish <folder>
publishes from cwd folder
#504
Comments
I just ran in to this as well. my stack:
This fails when running not through execa as well:
execa is on version 6 something -- could it be relateD? |
the range defined for this project's dependency on |
I made some research.
Same result, it maybe issue with npm itself (my version is 8.11.0), also I do no see any related bug fixes in changelog of execa (after v5) I've tried another trick: // npm publish --userconfig /tmp/xxx/.npmrc --tag latest --registry http://localhost:4873/ # {cwd: /root/packages/my-package/dist}
const result = execa( 'npm',
['publish', '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd: basePath, env, preferLocal: true}
); And it works! So it definitly something wrong with npm and |
execa
failsexeca
fails / npm publish <folder>
publishes from cwd folder
in your local test, did you execute directly from your dist directory, or with the same command that semantic-release is running and from the effective cwd? i'm wondering if what you are describing is either a breaking change in npm or a bug that should be reported to them.
the npm plugin for semantic-release defines a direct dependency on npm, so the version installed because of that would have more impact on this situation than your globally installed version. you can determine which version is locally installed with the command |
same command that semantic-release is running and from the effective cwd
Yes, sorry, it's my global version. |
In 1st comment I described behavior of underlying npm ([email protected]) |
Just got the exact same issue yesterday and took me the whole day to figure it out. This has nothing to do with Nonetheless, this can be fixed in |
execa
fails / npm publish <folder>
publishes from cwd foldernpm publish <folder>
publishes from cwd folder
@travi, would you accept a PR to fix that ? (ie. replace |
are you considering the
@unlight @NullVoxPopuli are you using npm workspaces in the projects where you encountered this situation? |
pnpm workspaces, but ya |
@travi, yes I'm considering it. What I meant is: Looking at the code here (publish.js#L26): const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;
[...]
const result = execa(
'npm',
['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd, env, preferLocal: true}
); We can see that :
But why would A fix to this issue (also suggested by @unlight) would be to make sure that Something like: 'npm',
['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd: basePath, env, preferLocal: true} or simply: 'npm',
['publish', '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd: basePath, env, preferLocal: true} |
…ublishes from cwd folder
As it is a blocking issue for me, I have made a PR to fix it. @travi, I would be very pleased if you could approve it. Thanks 🙏 |
any progress? 💦 |
For anyone interestedAs no action were taken here and it was blocking for me, I'm using this temporary fix : {
"scripts": {
"postinstall": "node patch-semantic-release-npm.js"
}
} patch-semantic-release-npm.js#L1-L24 /**
* TODO: this whole patch can be removed when https://github.com/semantic-release/npm/pull/531 is fixed
*/
const { readFileSync, writeFileSync, existsSync } = require('fs-extra');
const { green, red, gray } = require('@colors/colors/safe');
const { dirname, join } = require('path');
const filePath = join(dirname(require.resolve('@semantic-release/npm')), '/lib/publish.js');
if (existsSync(filePath)) {
let data = readFileSync(filePath, { encoding: 'utf8' });
if (!data.match(/cwd: basePath/gm)) {
data = data.replace("'publish', basePath,", "'publish',");
data = data.replace("cwd, env,", "cwd: basePath, env,");
writeFileSync(filePath, data, { encoding: 'utf8' });
console.log(green('success'), '@semantic-release/npm patched.');
} else {
console.log(green('success'), '@semantic-release/npm already patched.');
}
} else {
console.error(red('error'), 'cannot patch @semantic-release/npm.');
console.error(gray(`"${filePath}" not found`));
} |
I have configured
semantic-release/npm
withpkgRoot = './dist'
On CI/CD command is
npx -w my-package semantic-release
CI run 28 Logs:
Note:
[email protected]
is a result of npm publishCI run 29 Logs:
As you can see from logs version
1.1.2
is correctly written to package.json indist
folder, but following command is failingIt's trying to publish
0.0.0-dev.1
which is inpackage.json
in/root/packages/my-package
(equals toprocess.cwd()
)But if I execute this command locally, it works without errors.
Corresponding npm publish command:
Looks like that
execa
has issues withcwd
orpreferLocal
(or its combination).Update: Some additional research results here in https://github.com/semantic-release/npm/issues/504#issuecomment-1201540336
The text was updated successfully, but these errors were encountered: