preface

Search Google and related Github Repo Issues are not available, NPM workspace information is not much, some are yarn workspace said what installation dependency abnormal, changed to domestic Taobao source, come and go, said what source can not be found, a fierce operation, The problem is still unresolved. Only oneself grope, my solution posture felling should be whole net first case!

System environment

  • Mac OS
  • The Node 14.16.1
  • NPM 7.12.1
    • @ sentry/cli 1.64.2

Question list

sentry-cli ENOENT

ERROR in Sentry CLI Plugin: spawn /workspace/project/node_modules/@sentry/cli/sentry-cli ENOENT
Copy the code

not installed by @sentry/cli 

error: sentry-cli was not installed by @sentry/cli install script 
Copy the code

Struggling posture

NPMRC configuration source

sentrycli_cdnurl=https://npm.taobao.org/mirrors/sentry-cli/
Copy the code

Palliative, because in the monomer mode (not workspace), taobao source installation can be smooth and pretty fast… NPM 7 workspace still not found. Node_modules only installs a corrupted version of @sentry/cli, missing sentry-cli (binary execution file depending on system type).

Strong installation in the main project

Clear the cache and force the installation. All of them.
# Useless,
npm cache clean --force
rm -rf node_modules yarn.lock package-lock.json
npm install @sentry/cli  --force --legacy-peer-deps

# why --legacy-peer-deps
Since it is not a peer-dependent subpackage, regular install will throw the following exception
# ERESOLVE unable to resolve dependency tree
Copy the code

Installing the latest package

Having solved this problem,

error: sentry-cli was not installed by @sentry/cli install script 
Copy the code

Final solution (interim solution)

I went to node_modules/@sentry/cli and found that he had provided the installation script and ran a wave.

# exec
# I found that the logic inside is to determine what system is currently in use, download the corresponding binary
node ./node_modules/@sentry/cli/scripts/install.js

# As expected, the execution is completed. Sentry - CLI is back..

# validation
./node_modules/.bin/sentry-cli --help
It can output normally
Copy the code

Every time you do it manually? NO, NO, NO… NPM provides the prepare hook, which can be executed automatically after Install. NPM Scripts -> Life Cycle Scripts

package.json

  "scripts": {
    "prepare": "husky install; node check-sentry.js",},Copy the code

check-sentry.js

The e most direct is to write a JS logic decision file to the project root directory.

/* * 1. Execute part of the shell to determine * 2. 3. Go through the installation logic (if there is a cache, it will hit directly and output use cache....) * 4. Finally, the output version number. * / 
const { execSync } = require('child_process');
const { existsSync } = require('fs');
const { join } = require('path');

const basePath = process.cwd();
function getJoinPath(relativePath) {
  return join(basePath, relativePath);
}
const sentryCliBinPath = getJoinPath('./node_modules/.bin/sentry-cli');
const nodeModulesSentryInstallPath = getJoinPath('./node_modules/@sentry/cli/scripts/install.js');


const sleep = ms= > new Promise(resolve= > setTimeout(resolve, ms));
const SLEEP_TIME = 10000;


async function checkSentry() {
  const stdio = ['ignore'.'inherit'.'ignore'];
  if (existsSync(sentryCliBinPath)) {
    try {
      execSync(`${sentryCliBinPath} -V`, { stdio });
    } catch (error) {
      if (existsSync(nodeModulesSentryInstallPath)) {
        execSync(`node ${nodeModulesSentryInstallPath}`);
        await sleep(SLEEP_TIME);
        execSync(`${sentryCliBinPath} -V`, { stdio });
      }
    }
  }
}


checkSentry();


Copy the code

Finish scattering flowers, can normally package calls sentry upload sourcemap these

conclusion

If there is something wrong, please leave a message and correct it in time. Thank you for reading!