Set env in windows command line/ package.json - javascript

Am having issues running a react app on windows.
The app was initially setup to run on a macOS.Below are the error messages and package.json file.
Question:
How can I start and build PORT for windows?
package.json
{
"name": "tradingview-finnhub",
"private": true,
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.4.0",
"request-promise": "^4.2.5"
},
"scripts": {
"start": "PORT=8080 react-scripts start",
"build": "PORT=8080 react-scripts build"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Error message
'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! tradingview-finnhub# start: `PORT=8080 react-scripts start`
npm ERR! Exit status 1

You just need to add set before the PORT=8080 and a & after it.
It would be something like:
"scripts": {
"start": "set PORT=8080 & react-scripts start",
"build": "set PORT=8080 & react-scripts build"
},
The problem is that you need to set the environment variable of PORT before running the react-script, the solution I gave does that. For more info you can see:
https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt
How do I run two commands in one line in Windows CMD?

Related

Compile Error: Module Not Found. React with Clarifai API

I tried to compile my project and ended with this error message....
package.json
"name": "facerecognitionbrain",
"version": "0.1.0",
"private": true,
"dependencies": {
"clarifai": "^2.9.1",
"particles-bg": "^2.5.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-parallax-tilt": "^1.7.67",
"react-scripts": "^5.0.1",
"tachyons": "^4.12.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"web-vitals": "^3.1.1"
}
}
hope someone has a solution...thanks
Other suggestions I have tried is to copy package.json and package-lock.json from the github repo of our instructor, deleted all node_modules and re-installed with npm ci. It just reduced my errors to 2.
it seems you dont have these packages installed. You can try to run npm install clarifai-nodejs-grpc web-vitals.
Also deleting the package.lock.json and node_modules and running npm install again should work if you have these two packages listed on your package.json dependencies.
Added after addition of the package json to the question:
It seems from your package json that you have installed the clarifai package: github.com/Clarifai/clarifai-javascript, and not the clarifai-nodejs-grpc package: github.com/Clarifai/clarifai-nodejs-grpc.
Make sure to install the right one according to your use case, and use the right one on the code.
If you could also add how you are importing the package on your code, it could make things clearer. But it seems you are importing clarifai-nodejs-grpc package in the code while you have clarifai package installed.
According to their github you should use clarifai-nodejs-grpc
So:
remove the clarifai from the dependencies on you package json
run npm install
run npm install clarifai-nodejs-grpc

Npm start on offline win10

I have React project, created on MacOs and i want to run it on win10, but win10 computer in corp's LAN, so i cannot use "npm install" to download all dependencies. Hence i got all of them and builded project via Git, so for now on win10 i have all files are needed to "npm start".
But here are several errors, when i tried to run dev server or builded project:
npm start (== "react-scripts start")
'react-scripts' is not recognized as an internal or external command
npm start (== "node node_modules/.bin/react-scripts start")
Unexpected token '.'
Non of additional slashes before .bin to screening not helped.
npx serve -s build
network to registry.npmjs.org/serve failed.
Unclear why it needs internet at all, i just want to run builded project.
All of advices are to run "npm install" before "npm start", but i cannot connect to central artifactory from our LAN and i already have all of dependencies.
Hence, there are way to just start dev server or pack all project's files in some analogue of .jar totally without internet?
package.json
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#date-io/date-fns": "^1.1.0",
"#material-ui/core": "^4.11.0",
"arui-feather": "^18.4.0",
"axios": "^0.21.0",
"core-js": "^3.7.0",
"date-fns": "^2.0.0-beta.5",
"material-table": "^1.69.2",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-router": "latest",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

I am facing some vulnerabilities issue while deploying React App via NPM

New to React Js. Here is the short summary of my app, I created a small react app which filter the team members with the text input. It is working well in development environment. Which is working while start of NPM. Please check and where I am doing mistake or give me a chance to correctness of the process.
My project> NPM start
My site is loading in local or dev env.
Followed deployment process from this link. https://create-react-app.dev/docs/deployment/
But when I tried to deploy the site to GitHub, I am facing some vulnerabilities security issue. I have shared the step by step what I am currently doing. I see the issue is in the Mime Package. But I don`t know how to upgrade or degrade the package. Kindly check and guide in my wrong way.
My project> npm install --save gh-pages
My project>npm audit
Manual Review
Some vulnerabilities require your attention to resolve
Visit https://go.npm.me/audit-guide for additional guidance
Moderate Regular Expression Denial of Service
Package mime
Patched in >= 1.4.1 < 2.0.0 || >= 2.0.3
Dependency of git
Path git > mime
More info https://npmjs.com/advisories/535
found 1 moderate severity vulnerability in 1666 scanned packages
1 vulnerability requires manual review. See the full report for details.
But Facing issue when I try to deploy to github account. Can any one help me on this.
My Package.json is also attached
{
"name": "spiceliveteam",
"version": "0.1.0",
"homepage": "https://nachisgit.github.io/TeamMembers",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"git": "^0.1.5",
"npm-git-install": "^0.3.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"tachyons": "^4.12.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"gh-pages": "^3.1.0"
}
}
After a few hours of R and D. I recreated the package.json which solves my issue. Thanks for who respond to my answer. This will help full to some one.
For creating Package Kindly use npm init.
Add the dependencies from previous packages and then proceed with build and deploy. Happy coding.

React app fails to compile after installing 'node-sass'. How to fix "Module not found" error?

I've built an react.js app which runs fine before installing 'node-sass' using npm install.
The app runs normally in the production build but fails to compile in development build, when using npm start.
This problem doesn't occur with any other package except 'node-sass'
The app worked fine when I imported it to another PC and installed 'node-sass' there.
I tried reinstalling node and npm but to no avail.
I've uninstalled node-sass globally too.
This is my package.json:
"name": "my_app_name",
"version": "0.1.0",
"private": true,
"dependencies": {
"gh-pages": "^2.1.1",
"node-sass": "^4.12.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "npm run build && gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
This is the error message i keep getting:
Failed to compile.
./node_modules/react-dev-utils/formatWebpackMessages.js
Module not found: Can't resolve 'path\to\app\node_modules\babel-preset-react-app\node_modules\#babel\runtime/helpers/slicedToArray' in 'path\to\app\node_modules\react-dev-utils'
install node-sass globally and not as a package.
npm i node-sass

The "file" argument must be of type string. Received type undefined on npm run deploy to gh-pages [duplicate]

This question already has answers here:
Trying to deploy my React app with gh-pages but got this error message : The "file" argument must be of type string. Received type undefined
(2 answers)
Closed 3 years ago.
I was trying to deploy a react application to gh-pages. I've done it before, but this is the first time I'm getting this kind of error. It says
The "file" argument must be of type string. Received type undefined
I tried removing the node_modules folder and reinstalled all the packages with npm install, but still finding the same error
Below is my package.json file
{
"name": "qrummy",
"version": "0.1.0",
"homepage": "https://quiph.github.io/QRummy/",
"private": true,
"dependencies": {
"firebase": "^6.2.4",
"gh-pages": "^2.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
And this is my main index.js file
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
serviceWorker.unregister();
Error Output is as follows
qrummy#0.1.0 deploy /home/qtalkdev/Krunal/github/QRummy
> gh-pages -d build
The "file" argument must be of type string. Received type undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! qrummy#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the qrummy#0.1.0 deploy 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! /home/qtalkdev/.np`enter code here`m/_logs/2019-08-01T17_28_14_611Z-debug.log
It looks like the current version is not working. I faced the same problem today. Uninstall gh-pages module. Installed version 2.0.1 and it worked.

Categories