Giter Site home page Giter Site logo

Comments (4)

sindresorhus avatar sindresorhus commented on August 22, 2024 1

This looks like a problem with your build tool. You should open an issue there instead. node:os is a valid module specifier.

from fix-path.

linonetwo avatar linonetwo commented on August 22, 2024 1

Solution:

based on fix-path 4.0.0

import { execSync } from 'child_process';
import { userInfo } from 'os';
import process from 'process';
import stripAnsi from 'strip-ansi';

const defaultShell = (() => {
  const { env, platform } = process;
  if (platform === 'win32') {
    return env.COMSPEC ?? 'cmd.exe';
  }
  try {
    const { shell } = userInfo();
    if (shell !== undefined) {
      return shell;
    }
  } catch {}
  if (platform === 'darwin') {
    return env.SHELL ?? '/bin/zsh';
  }
  return env.SHELL ?? '/bin/sh';
})();

const arguments_ = ['-ilc', 'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit'];

const environment = {
  // Disables Oh My Zsh auto-update thing that can block the process.
  DISABLE_AUTO_UPDATE: 'true',
};

const parseEnvironment = (environment_: string): Record<string, string> => {
  environment_ = environment_.split('_SHELL_ENV_DELIMITER_')[1];
  const returnValue: Record<string, string> = {};

  for (const line of stripAnsi(environment_)
    .split('\n')
    .filter((line) => Boolean(line))) {
    const [key, ...values] = line.split('=');
    returnValue[key] = values.join('=');
  }

  return returnValue;
};

export function shellEnvironmentSync(shell?: string): NodeJS.ProcessEnv {
  if (process.platform === 'win32') {
    return process.env;
  }

  try {
    const stdout = execSync(`${shell ?? defaultShell} ${arguments_.join(' ')}`, { env: environment });
    return parseEnvironment(String(stdout));
  } catch (error) {
    if (shell !== undefined) {
      throw error;
    } else {
      return process.env;
    }
  }
}

export function shellPathSync(): string | undefined {
  const { PATH } = shellEnvironmentSync();
  return PATH;
}

export function fixPath(): void {
  if (process.platform === 'win32') {
    return;
  }
  process.env.PATH = shellPathSync() ?? ['./node_modules/.bin', '/.nodebrew/current/bin', '/usr/local/bin', process.env.PATH].join(':');
}

from fix-path.

sindresorhus avatar sindresorhus commented on August 22, 2024

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

from fix-path.

linonetwo avatar linonetwo commented on August 22, 2024

So finally how to solve this? I got .webpack/main/454.index.worker.js Error: Cannot find module 'node:process'

from fix-path.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.