MacOS react-native-macos execute shell commands

30 views Asked by At

Is there a way to run shell commands on react-native-macos?

const { exec } = require("child_process");

...
          exec("ls -la", (error, stdout, stderr) => {
            if (error) {
                console.log(`error: ${error.message}`);
                return;
            }
            if (stderr) {
                console.log(`stderr: ${stderr}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
        });

Error:

error: Error: While trying to resolve module `child_process` from file `/Users/userName/Desktop/dir/react-native-menubar-extra/example/src/App.tsx`, the package `/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js`. Indeed, none of these files exist:

  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js/index(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
    at DependencyGraph.resolveDependency (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js:272:17)
    at Object.resolve (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/lib/transformHelpers.js:177:21)
    at Graph._resolveDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
    at Graph._processModule (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
    at async Graph._traverseDependenciesForSingleFile (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:207:5)
    at async Graph.traverseDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:147:9)
    at async DeltaCalculator._getChangedDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:247:42)
    at async DeltaCalculator.getDelta (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:90:16)
    at async DeltaBundler.getDelta (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler.js:67:12)
    at async IncrementalBundler.updateGraph (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/IncrementalBundler.js:218:19)
 ERROR  [Error: InternalError Metro has encountered an error: While trying to resolve module `child_process` from file `/Users/userName/Desktop/dir/react-native-menubar-extra/example/src/App.tsx`, the package `/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js`. Indeed, none of these files exist:

  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js/index(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx): /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js (272:17)

  270 |         }
  271 |         if (error instanceof InvalidPackageError) {
> 272 |           throw new PackageResolutionError({
      |                 ^
  273 |             packageError: error,
  274 |             originModulePath: from,
  275 |             targetModuleName: to,]
Error: While trying to resolve module `child_process` from file `/Users/userName/Desktop/dir/react-native-menubar-extra/example/src/App.tsx`, the package `/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js`. Indeed, none of these files exist:

  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
  * /Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/child_process/index.js/index(.native|.macos.js|.native.js|.js|.macos.jsx|.native.jsx|.jsx|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
    at DependencyGraph.resolveDependency (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js:272:17)
    at Object.resolve (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/lib/transformHelpers.js:177:21)
    at Graph._resolveDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
    at Graph._processModule (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
    at async Graph._traverseDependenciesForSingleFile (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:207:5)
    at async Graph.traverseDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Graph.js:147:9)
    at async DeltaCalculator._getChangedDependencies (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:247:42)
    at async DeltaCalculator.getDelta (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:90:16)
    at async DeltaBundler.getDelta (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler.js:67:12)
    at async IncrementalBundler.updateGraph (/Users/userName/Desktop/dir/react-native-menubar-extra/example/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/IncrementalBundler.js:218:19)

Can you give me a hand?

0

There are 0 answers