package.json start scripts failing react - javascript

I have two package.json files, one in my root directory, and one in my react-web directory...
heres the scripts:
root directory package.json
"start": "cd react-web && npm run postinstall && export REACT_APP_CUSTOMER_ENVIRONMENT=gianlucaherokutest320880 && npm start"
react-web directory package.json
"start": "node --max_old_space_size=4096 react-app-rewired start",
it gives me this error:
Error: Cannot find module '/app/react-web/react-app-rewired'
However, I have react-app-rewired installed, and I deleted node_modules and npm install again already! Does anyone have any ideas?

Related

Accessing the script of package.json of a npm package from our project package.json file

I created a tool and registered it on npmjs.com named Yattex. It script looks something like this
`
"scripts": {
"clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mochareports ",
"pretest": "npm run clean:reports",
"scripts": "cypress run",
"combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports -- inline",
"posttest": "npm run combine-reports && npm run generate-report",
"yattex-tool": "node yattex-tool",
"decorator": "node yattex-tool/test-decorators",
"test": "npm run decorator && npm run scripts || npm run posttest || npm run yattex-tool"
},
`
Now, in another project i installed the package and now i dont know what to write in scrips(test) to run the above test command which is in the node_modules/yattex/package.json file
I tried yattex and node node_modules/yattex/package.json
But it doesn't work. I'm a newbie and i cant find any solution...
If you add a property
"workspaces": ["./node_modules/yattex"]
to the package.json file in your other project, then npm test --workspaces will execute the tests both in your other project and in the yattex project (which is a "workspace" as explained on the npm help run page).
If you want to run only the tests for yattex, use npm test --workspace=./node_modules/yattex.

How to run npm script (package.json) written in an external js file?

I know it has been covered in different questions but mine is a bit different:
Sorry in advance if it sounds really noob.
this is the script in package.json:
"start": "nodemon ./index.js --exec \"node -r babel-register\"",
I replaced that with:
"start": "node scripts/start.js",
and in start.js, I do:
const { execSync } = require('child_process')
execSync('nodemon ../index.js --exec \"node -r babel-register\"')
which throws an error:
/bin/sh: nodemon: command not found
Am I right with "execSync"?
I tried import nodemon in the file but it is obviously not helping.
What you're doing should work if nodemon is installed globally, i.e. with:
npm install -g nodemon
But if it's installed as a project dependency, i.e. with:
npm install --save-dev nodemon
Then you'll need to run it from the directory containing all the locally installed binaries: node_modules/.bin/
So something like this should work:
execSync('./node_modules/.bin/nodemon ../index.js --exec \"node -r babel-register\"')

How do I implement a nfc reader (ACR122) to an Electron project?

I have downloaded this library (https://github.com/pokusew/nfc-pcsc) and now i'm trying to run an Electron project in it, but is giving me everytime problems when i try to run it as an Electron project.
So my question is: How can I implement this library on my Electron project and make it work not as node.js
I tried to npm install --save electron#latest in the library and change on the json the script "example": "node -r #babel/register examples/read-write.js" to "example": "electron -r #babel/register examples/read-write.js" also i have tried to uninstall and install, i have done electron-rebuild
"rebuild": "electron-rebuild -f -w yourmodule",
"build": "babel src --out-dir dist",
"example": "electron -r #babel/register examples/read-write.js",
"example-basic": "node -r #babel/register examples/basic.js",
"example-from-readme-3": "node -r #babel/register examples/from-readme-3.js",
"example-led": "node -r #babel/register examples/led.js",
"example-mifare-classic": "node -r #babel/register examples/mifare-classic.js",
"example-mifare-desfire": "node -r #babel/register examples/mifare-desfire.js",
"example-mifare-ultralight-ntag": "node -r #babel/register examples/mifare-ultralight-ntag.js",
"example-ndef": "node -r #babel/register examples/ndef.js",
"example-uid-logger": "node -r #babel/register examples/uid-logger.js",
"example-without-auto": "node -r #babel/register examples/without-auto.js",
"prepack": "yarn build && yarn test",
"test": "cross-env NODE_ENV=test ava test/tests.js --verbose"
}
I'm getting this error when i'm trying to run the app as Electron app (https://i.imgur.com/UhSjlo6.png) and when i do the rebuild i have this error: × Rebuild Failed An unhandled error occurred inside electron-rebuild
Electron as of v5.0.0 is using Node.js v12.0.0. This native module (nfc-pcsc) is not building correctly for that version.
Downgrade Electron to v4, rebuild via "electron-rebuild" and it should build properly.
npm install --save-dev electron#4
then
electron-rebuild

Npm scripts always gives an error as "is not recognized as an internal or external command"

I have a lerna repo. There is devDependency to concurrently package from my root package.json. When I type "lerna bootstrap" to command line, it works properly and install all root and subPackages` dependencies to root node_modules folder. But when i type "npm start" it says: 'concurrently' is not recognized as an internal or external command. When i check node_modules/concurrently folder it exists without problem.
My start script is concurrently --kill-others "npm run start-client" "npm run start-server".
This situation same with webpack-dev-server. How can i fix this problem except reinstalling everything.
package.json:
{
"name": "x-workspace",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"concurrently": "3.5.0",
"lerna": "^2.11.0"
},
"scripts": {
"start": "concurrently --kill-others \"npm run start-client\" \"npm run start-server\"",
"build": "webpack --hot",
"start-client": "npm --prefix ./packages/client-app start",
"start-server": "cd ./packages/server-app && dotnet run",
"clean": "rimraf node_modules package-lock.json ./packages/client-app/package-lock.json"
}
}
I found problem. There is no .bin folder in root node_modules folder. This is result of updating yarn to 1.8.0. When i return back to yarn 1.6.0, it works perfectly.
Thanks to David R. and other users.
I believe you don't have the concurrently package installed globally, To confirm try executing the below command and check if it returns anything,
npm list -g concurrently
If you've received an --(empty) response, then you'll have to install it globally.
npm install -g concurrently
Hope this helps!.

Express.js + lint gives mistake

https://www.youtube.com/watch?v=Fa4cRMaTDUI
I am watching this lesson and trying to recreate everything author does. At 19:00 he sets vue.js-express.js project. He creates folder called 'server'. In 'server/' he runs 'npm init -f'. Then 'npm install --save nodemon eslint', then he inits eslint.
Then in package.json file he writes:
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
}
Then in folder 'server' he creates folder 'src'. In 'src' he creates 'app.js'. And in 'app.js; there is a simple console.log('hello').
Then he runs 'npm start'. 'Hello' is printed in terminal, nodemon and eslint works just fine. Then he types 'npm install --save express'. Thats where my problem begins. After installing express.js i type 'npm start' and i get this error in terminal:
Oops! Something went wrong! :(
ESLint: 5.0.0.
No files matching the pattern "node_modules/ipaddr.js" were found.
Please check for typing mistakes in the pattern.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! server#1.0.0 lint: `eslint **/*.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the server#1.0.0 lint 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/r/.npm/_logs/2018-06-25T10_32_02_027Z-debug.log
[nodemon] process failed, unhandled exit code (2)
[nodemon] Error
at Bus.utils.bus.on (/home/r/projects/tab-tracker/server/node_modules /nodemon/lib/nodemon.js:148:25)
at Bus.emit (events.js:164:20)
at ChildProcess.<anonymous> (/home/r/projects/tab-tracker/server/node_modules/nodemon/lib/monitor/run.js:164:11)
at ChildProcess.emit (events.js:159:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
Why is this happening?
Quote the pattern and it works fine as in previous versions of eslint
"lint": "eslint \"**/*.js\""
Credit goes to
https://github.com/eslint/eslint/issues/10599
#joknawe in comments gave right answer, thanks.
edit:
Looks like maybe it is trying to lint your node_modules directory. This should be ignored by default, but your wildcard **/*.js may be causing the issue. Try just using eslint
Replace your code
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
for
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint"
I use WSL and i fixed by changing following line.
Previous
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint **/*.js"
After
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint src/**/*.js --fix"
In a Mac I fixed it just changing the following line
Previous
"lint": ""lint": "./node_modules/.bin/eslint **/*.js""
After
"lint": "./node_modules/.bin/eslint src/*.js"
Just add quotes around the wildcard **/*.js.
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
}
in .eslint.js file you should replace this code
Before
"browser": true
After
"node": true

Categories