npm: command not found when executing commands in Electron app - javascript

I'm working on an electron app and within the app, I execute shell commands using child_process.exec. One of the commands I run is npm run start; this works perfectly in a dev environment but when I build the application for production all npm commands fail with showing the following error:
Error: Command failed: npm run start
/bin/sh: npm: command not found
at ChildProcess.exithandler (child_process.js:287)
at emitTwo (events.js:126)
at ChildProcess.emit (events.js:214)
at maybeClose (internal/child_process.js:925)
at Socket.stream.socket.on (internal/child_process.js:346)
at emitOne (events.js:116)
at Socket.emit (events.js:211)
at Pipe._handle.close [as _onclose] (net.js:554)
I tried running the application in debug mode by running the following command open MyApp.app/Contents/MacOS/MyApp and the npm commands run successfully with no errors.
What could be the issue?

The issue that the environment variable of $PATH is wrong inside the packaged app, it works in development because the application is launched from the terminal which gives it access to the $BASH profile.
To solve this problem I used this package fix-path. I installed the package and added the following snippet at the top of the file
if (process.env.NODE_ENV === 'production') {
const fixPath = require('fix-path');
fixPath();
}
I came to this answer after going through this issue on GitHub. Thanks to #Seblor

Related

Facing problem during installing react project and setting up of Node Js

I am trying to setup a ReactJS app on Windows using the following command in Git Bash:
npx create-react-app my-app
and the output is coming as :
`Creating a new React app in C:\Users\Dell\desktop\react-portfolio-website-1.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting react-portfolio-website-1/ from C:\Users\Dell\desktop
node:fs:1226
return handleErrorFromBinding(ctx);
^
Error: EBUSY: resource busy or locked, rmdir '\?\C:\Users\Dell\desktop\react-portfolio-website-1'
at rmdirSync (node:fs:1226:10)
at _rmdirSync (node:internal/fs/rimraf:235:5)
at rimrafSync (node:internal/fs/rimraf:193:7)
at Object.rmSync (node:fs:1275:10)
at Object.removeSync (C:\Users\Dell\AppData\Local\npm-cache_npx\c67e74de0542c87c\node_modules\fs-extra\lib\remove\index.js:15:28)
at C:\Users\Dell\AppData\Local\npm-cache_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:539:14
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
errno: -4082,
syscall: 'rmdir',
code: 'EBUSY',
path: '\\?\C:\Users\Dell\desktop\react-portfolio-website-1'
}
Node.js v18.12.1
`
I always face this problem, expected to get new react js project.
Are you on VPN or do you have any antivirus installed. Try disabling it and then running npx create---
I had almost same issue, I had to change my terminal for VSCode from Powershell to bash, then I ran these commands and it worked.
npm cache clean --force
npx create-react-app (project name)
Hope this should help you

Getting Error after installing react native firebase storage

So I was working with my React Native application and had to install react-native firebase storage for image storing. So I ran npm install #react-native-firebase/storage after installing it I re-run my server and after that, I am getting this error. I don't know why I am getting this error. Kindly help me out.
Getting this error:
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
F:\Salvador\node_modules\#react-native-firebase\storage\android\src\main\java\io\invertase\firebase\storage\ReactNativeFirebaseStorageModule.java:234: error: cannot find symbol
firebaseStorage.useEmulator(host, port);
^
symbol: method useEmulator(String,int)
location: variable firebaseStorage of type FirebaseStorage
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-firebase_storage:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
at makeError (F:\Salvador\node_modules\execa\index.js:174:9)
at F:\Salvador\node_modules\execa\index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (F:\Salvador\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (F:\Salvador\node_modules\react-native\node_modules\#react-native-community\cli\build\index.js:186:9)
info Run CLI with --verbose flag for more details.
When I run my server I get this error
info Run CLI with --verbose flag for more details.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Salvador#0.0.1 android: `react-native run-android`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Salvador#0.0.1 android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Home\AppData\Roaming\npm-cache\_logs\2021-06-02T14_16_46_571Z-debug.log
If anyone else is getting this error what you need to do is open your react native android folder in Android Studio and then build and run your application via Android Studio. It will successfully run the project after that close Android Studio and now again start your react native project.
Now you will get 0 errors.
Also, run npm outdated after running that try upgrading your outdated packages also as my storage version was 12.0 but auth and app of firebase was 11.2.

What is needed to create react app offline?

I am working offline without any internet connectivity. I have Node.js installed on my system. When I try to run the npm create-react-app command it gives me an error. Is there any way for me to run npm commands and get react application running offline? If I create react app on another computer (with an internet connection) and took that in my PC via pen drive, will it work? Below is the error code I get:
npm ERR! errcode ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/create-react-app failed,
reason: getaddrinfo ENOTFOUND registry.npmjs.org
In your question, I saw that you are using the command npm create-react-app. I think, it should be npx create-react-app.
NPM by itself does not simply run any package. it doesn't run any package in a matter of fact.
npx will check whether exists in $PATH, or in the local project binaries, and execute it
And if you run the create react app function on another computer (with internet connection) and take that to your PC via pen drive, it will work.

Unexpected token Function : Async Function

I am having issue deploying a application developed in node js. It uses Docker framework and is being deployed on Pivotal.
On pushing the app to Pivotal I get the following error
/home/vcap/app/node_modules/popsicle-transport-http/dist/index.js:372
return async function (req, next) {
SyntaxError: Unexpected token function,
Which prevents the app from starting.
Now I understand that the error can be caused due to the version of node not supporting async call. The app is not developed by me but it's upon me to deploy it on Pivotal.
I have ran the following commands to update npm and node
npm install -g npm stable
npm install -g node
and checked versions
npm -v
v6.10.2
node -v
v10.15.1
Then build the solution
docker build -t helloworld .
Then pushed the app to pivotal which produces the above error.
I have looked at the git page for popsicle and can't see anything been discussed on similar issue.
Any suggestions?

Unable to call npm run build using vue-cli in production

Expected Behavior
npm run build should create the production dist bundle that I can serve on a given machine
Current Behavior
Despite being able to build locally, whenever I try to run npm run build on an external resource (such as a Digital Ocean VM or Heroku machine), I receive the below error.
Failure Logs
root#nodejs-lazyq-dev:/var/www/html/Vue# npm run build
> vue-material-dashboard-pro#1.0.0 build /var/www/html/Vue
> vue-cli-service build
⠴ Building for production...
ERROR Failed to compile with 1 errors 09:29:00
error in ./src/assets/scss/_material-dashboard.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):
#import "md/plugins/fullCalendar";
^
File to import not found or unreadable: md/plugins/fullCalendar.
in /var/www/html/Vue/src/assets/scss/_material-dashboard.scss (line 59, column 1)
at runLoaders (/var/www/html/Vue/node_modules/webpack/lib/NormalModule.js:286:20)
at /var/www/html/Vue/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /var/www/html/Vue/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/var/www/html/Vue/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at Object.asyncSassJobQueue.push [as callback] (/var/www/html/Vue/node_modules/sass-loader/lib/loader.js:55:13)
at Object.done [as callback] (/var/www/html/Vue/node_modules/neo-async/async.js:7974:18)
at options.error (/var/www/html/Vue/node_modules/node-sass/lib/index.js:294:32)
# ./src/material-dashboard.js 17:0-48
# ./src/main.js
# multi ./src/main.js
ERROR Build failed with errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-material-dashboard-pro#1.0.0 build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-material-dashboard-pro#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-03T09_29_01_030Z-debug.log
Additionally, I have tried running npm rebuild node-sass, updated the material-dashboard.css file to include the underscore: _material-dashboard.css, passing --production in npm install --production, but am having no luck.
nodejs version: v8.11.4
npm version: v5.6.0
I've been trying to solve this for a few hours now but am not having any luck. I don't understand why it works locally but not when on another production machine.
This happens because of a spelling mistake (wrong case) in the import statement of this Vue UI library. The file is named "fullcalendar" while the import is called by "fullCalendar" (notice the capital "C"). When you fix this (make the capital "C" simple in the import statement) it will run the "npm run prod" command successfully. It should be noted that, for me, this did not occur in the windows environment for some reason, but only occurs in the Linux environment.

Categories

Resources