npm install webpack config.js - reactjs

Here is my package.json file and im trying to run command - 'npm run webpack'.
{
"name": "react-graphql2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server",
"dev-https": "webpack-dev-server --https",
"prettier": "prettier --write './{src,tests}/**/*.{ts,tsx,js,jsx,json,css,scss}'",
"start": "yarn run build",
"test": "jest --coverage",
"testDev": "jest"
When I run this command I get the below output and the package is built without issues-
laks2#1976190:~/projects/spa-test/react-graphql2$ npm run build
> react-graphql2#1.0.0 build /Users/laks/projects/spa-test/react-graphql2
> webpack
webpack.config.js
clean-webpack-plugin: /Users/laks/projects/spa-test/react-graphql2/dist/js/*.js has been removed.
Now, I move the same project to a different folder and run the same command, now I dont see the webpack.config.js being passed -
laks2#1976190:~/projects/spa-test/react-graphql2$ npm run build
> react-graphql2#1.0.0 build /Users/laks/projects/spa-test/react-graphql2
> webpack
clean-webpack-plugin: /Users/laks/projects/spa-test/react-graphql2/dist/js/*.js has been removed.

Related

error when run script trough npm run, but didn't when run directly

Im getting strange error when running lint script on my react js project
npm run lint
it gave me an error
'.' is not recognized as an internal or external command,
operable program or batch file.
but when I run the script directly on the terminal
./node_modules/.bin/eslint src --ext .ts,.tsx
there's no error
16 problems (0 errors, 16 warnings)
this is the package.json
{
"name": "g-frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode production",
"dev": "webpack-dev-server --mode development --open --hot",
"lint": "./node_modules/.bin/eslint src --ext .ts,.tsx",
"ts-build": "tsc --noEmit --project tsconfig.json"
"build-storybook": "build-storybook"
},
"keywords": [],
"author": "",
"license": "ISC",
}
npm version : 8.1.2
does anyone ever encounter same problem or have a solution?

How to create a package.json script that runs a file from node_modules?

I have installed the react-clear-cache package and in the docs it says that I need to add a new script to my package.json.
This is my package.json scripts:
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"prebuild": "npm run generate-build-meta",
"generate-build-meta": "./node_modules/react-clear-cache/bin/cli.js"
},
According to the docs I need to run npm run generate-build-meta but everytime I try, node tells me that it wasnt able to find "./node_modules/react-clear-cache/bin/cli.js"
What I should do to correctly run this cli.js?
By the way, I have the react-clear-cache in my node_modules and I can see the cli.js
This is the message I receive:
It is pretty much saying that '.' is not recognized as an internal command.
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"prebuild": "npm run generate-build-meta",
"generate-build-meta": "react-clear-cache"
},
Accessing node_modules binaries by path is unnecessary in package.json scripts. Within the package.json, you can proceed as though node_modules/**/bin/ is in your $PATH.

Getting error on deploying nestjs app on gcloud

Getting error on deploying nestjs app on google app engine. The deployment worked fine but app is giving error
Here is the my package.json file
"main": "dist/main.js",
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"prebuild": "rimraf dist",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node ./dist/main.js",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"build": " tsc -p tsconfig.build.json",
"gcp-build": "npm run build"
},
and this my app.yaml file
runtime: nodejs10
env: standard
I tried to see the error on gcloud console by gcloud app logs read and it gives me error in cjs/loader file
The app is working fine locally. Any reason why this is happening?
Error: Cannot find module 'src/utils'
It looks like you are using non-relative imports and using src as a root, which won't work once you have transpiled from typescript to javaScript without some extra modifications. The src directory shouldn't exist when you are in your production environment, only the dist that has your JavaScript. If you change the import to be a relative one (using .. to get tot the correct directory from where you are) it should work just fine

React Material start script NODE_PATH not recognized

I have downloaded following React Material template
template
Followed steps from documentation
package.json
{
"name": "material-dashboard-react",
"version": "1.6.0",
"description": "Material Dashboard React. Coded by Creative Tim",
"private": false,
"main": "dist/index.js",
"scripts": {
"start": "NODE_PATH=./src react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"lint:check": "eslint . --ext=js,jsx; exit 0",
"lint:fix": "eslint . --ext=js,jsx --fix; exit 0",
"build-package-css": "cp src/assets/css/material-dashboard-react.css dist/material-dashboard-react.css",
"build-package": "npm run build-package-css && babel src --out-dir dist"
},
}
Getting the following error
It is because you are using Windows. The project was likely ran on unix based computers before (NODE_PATH=./src is not a windows way of defining environment variables). You can either fix it by using the Windows syntax "start": "set NODE_PATH=./src react-scripts start", (your project will not run on unix machines) or use a cross-env library for defining your environment : https://www.npmjs.com/package/dotenv
For anyone wondering, I had the same issue with the same template and my solution was to configure a file in the project root as specified in this link.
I'm using docker and my working directory is in the /app directory, so I added this line in my tsconfig.json file at the root of my react app folder:
"compilerOptions": {
...,
"baseUrl": "/app/src",
}

build failed: exit code 127

created my project with my app
This is the project.json file. That I have created
{
"name": "detox",
"version": "0.0.1",
"private": true,
"scripts": {
"ios": "react-native run-ios",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test:e2e":"navicotrackapp test",
"test:e2e:build":"navicotrackapp build"
},
"dependencies": {
"react": "16.6.1",
"react-native": "0.57.7"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.49.2",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
},
"detox": {
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/navicotrackapp.app",
"build": "xcodebuild -project ios/navicotrackapp.xcodeproj -scheme navicotrackapp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone XR"
}
}
}
}
However. When I ran the test this was the out come:
Questions:
What did I do wrong
How do I fix it?
For those coming with yarn 127 error code problem
Take a look on https://github.com/reactstrap/reactstrap/issues/711
Most probably you just need to run in console yarn :)
Replace your scripts values with these, and try again:
"scripts": {
"ios": "react-native run-ios",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test:e2e":"npm run test",
"test:e2e:build":"npm run build" // THIS SCRIPT WILL STILL BREAK FOR YOU
},
The last two are the important ones!
You need to prefix a script command with npm run or yarn if the script references another script in your package.json.
So instead of a script calling navicotrackapp test it would call npm run test OR yarn test.
NOTE:
In you example it looks like the terminal is failing on the script navicotrackapp build. Know that you do not have a build script defined so if you replace the script with npm run build it will still fail. You'll need to add a build script in if you want it to work!
"scripts": {
"ios": "react-native run-ios",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"build": // DO SOMETHING HERE!!!!,
"test:e2e":"npm run test",
"test:e2e:build":"npm run build"
},
Try below commands it works for me
$ npm install #ionic/app-scripts#latest --save-dev
$ ionic serve
Just use https://app.netlify.com/drop to deploy manually on Netlify
first run this command
npm run build
OR
yarn run build
Then drag and drop the build folder on the website above.
Try this, and please take care of the spaces.
It worked for me though. I added CI= in the capital before npm run build. Double-check if you did git add. , git commit -m "first commit" and git push -u origin before your final deployment.

Resources