Open unlight opened 2 years ago
I just ran in to this as well.
my stack:
at makeError (<repo>/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/error.js:60:11)
at handlePromise (<repo>/node_modules/.pnpm/execa@5.1.1/node_modules/execa/index.js:118:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async module.exports (<repo>/node_modules/.pnpm/@semantic-release+npm@8.0.3_semantic-release@18.0.1/node_modules/@semantic-release/npm/lib/prepare.js:21:3)}
This fails when running not through execa as well:
❯ npm version 6.1.2 --userconfig /tmp/28e1f8c78e58a4699a9d64a8774e2e50/.npmrc --no-git-tag-version --allow-same-version
ember-statechart-component
v6.1.2
npm ERR! Cannot read properties of null (reading 'matches')
execa is on version 6 something -- could it be relateD?
execa is on version 6 something -- could it be relateD?
the range defined for this project's dependency on execa
does not allow v6, so something is misconfigured in your project. you will need to resolve that first before further investigation could be done within the context of semantic-release
I made some research. I patched node_modules/@semantic-release/npm/lib/publish.js
const command = `npm publish ${basePath} --userconfig ${npmrc} --tag ${distTag} --registry ${registry}`;
require('child_process').execSync(command);
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 npm publish <folder>
command, npm publish
for current folder works ok.
But if I execute this command locally, it works without errors.
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.
my version is 8.11.0
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 npm ls npm
. if you are using our recommendation of executing with npx
instead of installing locally to your project, that would mean that the latest version within the defined range will be used.
But if I execute this command locally, it works without errors.
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?
same command that semantic-release is running and from the effective cwd
my version is 8.11.0
Yes, sorry, it's my global version. npm ls npm
shows npm@8.15.1
i'm wondering if what you are describing is either a breaking change in npm or a bug that should be reported to them.
In 1st comment I described behavior of underlying npm (npm@8.15.1) In research global npm was used. Same results.
Just got the exact same issue yesterday and took me the whole day to figure it out.
This has nothing to do with execa
and is more related to an npm
issue while using workspaces
.
You can see the detailed explanation and reproducible repo here : https://github.com/npm/cli/issues/5745.
Nonetheless, this can be fixed in @semantic-release/npm
by replacing cwd
with cwd: basePath
here: publish.js#L26.
As I don't see why the publish command should be executed from a different cwd anyway...
@travi, would you accept a PR to fix that ? (ie. replace cwd
with cwd: basePath
)
As I don't see why the publish command should be executed from a different cwd anyway...
are you considering the pkgRoot
option in that statement?
This has nothing to do with
execa
and is more related to annpm
issue while usingworkspaces
.
@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 :
basePath
is the final dist
location (nb: it is taking pkgRoot
into account)execa
is executed from cwd
npm publish
command is given a basePath
to publishBut why would execa
be executed from a different path than basePath
?
A fix to this issue (also suggested by @unlight) would be to make sure that execa
is executed directly from the dist
path.
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}
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? 💦
As 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 isnpx -w my-package semantic-release
CI run 28 Logs:
Note:
my-package@0.0.0-dev.1
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