Error: webpack-dev-server with ReactJS and Django - reactjs

I try to create a full stack environment with Django + ReactJS. Here, I use Webpack bundler and I'm getting this error while I try to run my webpack-server from a virtualenv. I'm very new to the application development and this is my first attempt, So can anyone help me out?
PS C:\Users\NikhileshSubramanian\Desktop\eduWebApp\env\frontend> npm run dev
frontend#0.1.0 dev C:\Users\NikhileshSubramanian\Desktop\eduWebApp\env\frontend
webpack-dev-server
module.js:549
throw err;
^
Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\NikhileshSubramanian\node_modules\html-webpack-plugin\lib\compiler.js:9:28)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend#0.1.0 dev: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend#0.1.0 dev 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\NikhileshSubramanian\AppData\Roaming\npm-
cache\_logs\2018-09-29T07_48_56_942Z-debug.log
Scripts inside my package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"buildwebpack": "webpack",
"dev": "webpack-dev-server"
},
"devDependencies": {
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"
}
Project Working Directory
https://i.stack.imgur.com/z1v0p.png

I saw that you are using windows system.So maybe you need configure environment variables for this "webpack/lib/node/NodeTemplatePlugin" module. Then it can find the module.

Webpack is inbuilt in React modules when we create a project via create-react-app. That's how Facebook has developed to reduce concentrating about environment setup and look into building the application. So, there's an easy way to create our project avoiding Webpack initiation.
Refer:
https://www.techiediaries.com/react-tutorial/

Related

Cannot find module 'webpack-cli/bin/config-yargs' - React

I'm trying to create react app without using create-react-app. Its throwing this error. Even in package.json scripts it tried changing the webpack-dev-server to webpack serve but its not working
could someone please help me. thanks
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
},
Require stack:
- C:\Users\aksha\Projects\onit-react-app\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\aksha\Projects\onit-react-app\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\aksha\\Projects\\onit-react-app\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! onit-react-app#1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the onit-react-app#1.0.0 start 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\aksha.DESKTOP-8T3GO8B\AppData\Roaming\npm-cache\_logs\2021-01-24T01_41_09_251Z-debug.log
Please update webpack-cli to v4 and use webpack serve to run webpack-dev-server
npm install webpack webpack-cli --save-dev

I tried using React using create-react-app

This is what I am getting error message.
If anybody can help or can point me to
How to Create a webpage using React served via an express nodejs server without "create react app" or anything like that, just plain vanilla express server serving a react app bundled by any transpiler.
$ npm start
> writer-babu#1.0.0 start C:\Users\kiit\Desktop\writer-babu
> webpack-dev-server --mode development --open --hot
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- C:\Users\kiit\Desktop\writer-babu\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\kiit\Desktop\writer-babu\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\kiit\\Desktop\\writer-babu\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! writer-babu#1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the writer-babu#1.0.0 start 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\kiit\AppData\Roaming\npm-cache\_logs\2020-11-26T05_15_56_534Z-debug.log
If anybody can help or can point me to
How to Create a webpage using React served via an express nodejs server without "create react app" or anything like that, just plain vanilla express server serving a react app bundled by any transpiler.

Create React project from another React project(template)

i use command line to create a new project for react :
npx create-react-app templatereact
... oky it's create for me a 'templatereact' project and downloaded 130 mb file
now again when i want to create a new project with 'create-react-app' i should to download 130 mb again and again and if i don't have internet i cant't create new project with 'create-react-app'
for this reason i want to create a new project from 'templatereact' for that I copied the entire folder 'templatereact' to new place and rename it to 'myreact' folder and in package.json i change name from "name": "templatereact", to "name": "myreact",. now when i run 'npm start' i give erros :
> myreact#0.1.0 start C:\tutorial\React&Redux\myreact
> react-scripts start
'\myreact\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module 'C:\tutorial\react-scripts\bin\react-scripts.js'
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)←[39m
←[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)←[39m
←[90m at internal/main/run_main_module.js:17:11←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myreact#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myreact#0.1.0 start 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\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-10T05_11_53_505Z-debug.log
now I don't know what other configurations I need to make on the new project 'myreact'.
Please tell me what configuration I need to do ??
You may want to check the package.json file which has a bunch of startup scripts / shortcuts defined.
Lookout for something like this:
"scripts": {
"start": "npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build",
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --
include-path ./node_modules src/ -o src/ --watch --recursive",
"build-css": "node-sass-chokidar --include-path ./src --include-path
./node_modules src/ -o src/",
"start-js": "react-scripts start"
},
And check whether the absolute path is same as the path of your new project. From the error it seems like it is not able to fine the react-scripts.js file.

Pushing React client and Rails API to Heroku, I'm hitting an error with the build script

I recognize that there are several questions out there with a similar/same issue, but I have not been able to find a working solution from those posts yet. When running git push heroku master, the build runs for a while, then crashes with the following error:
> client#0.1.0 build /tmp/build_f22760141a320d80dbbda0a359da5e4b/client
> react-scripts build
/tmp/build_f22760141a320d80dbbda0a359da5e4b/client/node_modules/#hapi/hoek/lib/deep-equal.js:17
options = { prototype: true, ...options };
^^^
SyntaxError: Unexpected token ...
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:513:28)
(it goes on for a bit more)
npm ERR! Linux 4.4.0-1048-aws
npm ERR! argv "/tmp/build_f22760141a320d80dbbda0a359da5e4b/.heroku/node/bin/node" "/tmp/build_f22760141a320d80dbbda0a359da5e4b/.heroku/node/bin/npm" "run" "build"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! client#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client#0.1.0 build script 'react-scripts build'.
There is more to it above and below, but I believe that is the relevant portion. My suspicion from reading this and other errors is that my package.json file is not set up correctly. Here is what I hope are the helpful portions to see:
// root package.json:
...
"engines": {
"node": ">= 6.9.4",
"npm": ">= 4.4.0"
},
"scripts": {
"start": "react-scripts start",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "cd client && npm install && npm run build && cd ..",
"deploy": "cp -a client/build/. public/",
"postinstall": "npm run build && npm run deploy && echo 'Client built!'"
},
...
// and /client/package.json:
...javascript
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
...
I was following this article while structuring my app, and it all went well until the deploy to Heroku.
Here are some other potentially useful things to note:
// Profile
web: bundle exec rails s
// Heroku buildpacks:
1. heroku/nodejs
2. heroku/ruby
// Node and npm are both updated
This is my first question on here, so I am sorry if there is insufficient or unnecessary information. Any help on where to look to fix this would be greatly appreciated. Thank you!
Well, it is working now, and all I did was:
git add .
git commit -m "Working on setting up Heroku. It's not working"
git push origin master
Then when I ran git push heroku master, it built! My guess is that Heroku was watching for changes to my master branch, and all the work I did reading other people's posts was never pushed to master. Very much a guess on that though.

Why i am getting this error in Command Line every time i create a react app and run with "npm start"?

From some time i am always getting an error in Command Line related to my react-scripts when i run my react app using the command "npm start".I tried many solutions but nothing seem to work(like deleting node_module and reinstalling and also changing my "react-scripts" version in package.json file.The error is:
E:\MYPROJECT\react-chat-app>npm start
> react-app#0.1.0 start E:\MYPROJECT\react-chat-app
> react-scripts start
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './util/escape'
at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (E:\MYPROJECT\react-chat-app\node_modules\cross-
spawn\lib\parse.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js
(internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-app#0.1.0 start 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\Acer\AppData\Roaming\npm-cache\_logs\2019-07-
07T13_59_34_897Z-debug.log
And here is my package.json file
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#pusher/chatkit": "^0.7.12",
"bootstrap": "^4.1.1",
"chatkit": "0.0.1-security",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "^3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Before this i wasn't having any such errors and my app used to run without such problems.But now even my already created app show this error when i run it.
I don't see in your package.json module util. Try install it npm i util

Resources