docmirror/dev-sidecar · warning

暂未实现此功能

Error message

暂未实现此功能

What it means

`get-npm-env` exposes a shell helper that returns the npm environment (registry/proxy settings) by invoking npm commands. Only the Windows handler is implemented; `linux` throws `暂未实现此功能` (not yet implemented). It is a known feature gap, not a runtime fault.

Source

Thrown at packages/core/src/shell/scripts/get-npm-env.js:19

/**
 * 获取环境变量
 */
const jsonApi = require('@docmirror/mitmproxy/src/json')
const Shell = require('../shell')

const execute = Shell.execute

const executor = {
  async windows (exec) {
    const ret = await exec(['npm config list --json'], { type: 'cmd' })
    if (ret != null) {
      const json = ret.substring(ret.indexOf('{'))
      return jsonApi.parse(json)
    }
    return {}
  },
  async linux (exec, { port }) {
    throw new Error('暂未实现此功能')
  },
  async mac (exec, { port }) {
    throw new Error('暂未实现此功能')
  },
}

module.exports = async function (args) {
  return execute(executor, args)
}

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Implement the linux handler: run `npm config get registry`/`npm config list --json` and parse with jsonApi, mirroring the win handler.
  2. Read npm config directly in your own code (`npm config list --json` via child_process) instead of the library helper.
  3. Use this helper only on Windows; feature-detect by platform first.

Example fix

// before
const env = await DevSidecar.shell.getNpmEnv({ port })
// after
let env = {}
if (process.platform === 'win32') {
  env = await DevSidecar.shell.getNpmEnv({ port })
} else {
  const { execSync } = require('child_process')
  env = JSON.parse(execSync('npm config list --json').toString())
}
Defensive patterns

Strategy: fallback

Validate before calling

if (process.platform === 'win32') {
  const env = await DevSidecar.shell.getNpmEnv({ port })
} else {
  const env = JSON.parse(require('child_process').execSync('npm config list --json').toString())
}

Type guard

function supportsNpmEnvHelper () {
  return process.platform === 'win32'
}

Try / catch

try {
  env = await DevSidecar.shell.getNpmEnv({ port })
} catch (err) {
  if (err.message === '暂未实现此功能') {
    env = JSON.parse(execSync('npm config list --json').toString())
  } else { throw err }
}

Prevention

When it happens

Trigger: Calling the get-npm-env shell API (e.g. `DevSidecar.shell.getNpmEnv`) on Linux, which dispatches to the placeholder `linux` handler in packages/core/src/shell/scripts/get-npm-env.js:19.

Common situations: Node plugin GUI page on a Linux desktop trying to read npm environment; shared automation that reads npm env across platforms.

Related errors


AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31). Data as JSON: /api/errors/cb11cc3db905ab02. Report an issue: GitHub.