简体   繁体   English

错误:使用ReactJS和Django的webpack-dev-server

[英]Error: webpack-dev-server with ReactJS and Django

I try to create a full stack environment with Django + ReactJS. 我尝试使用Django + ReactJS创建一个全栈环境。 Here, I use Webpack bundler and I'm getting this error while I try to run my webpack-server from a virtualenv . 在这里,我使用Webpack捆绑程序,并且在尝试从virtualenv运行我的webpack-server时遇到此错误。 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; 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 我的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 项目工作目录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. 我看到您正在使用Windows系统。因此,可能需要为此“ webpack / lib / node / NodeTemplatePlugin”模块配置环境变量。 Then it can find the module. 然后可以找到该模块。

Webpack is inbuilt in React modules when we create a project via create-react-app . 当我们通过create-react-app创建项目时,Webpack内置在React模块中。 That's how Facebook has developed to reduce concentrating about environment setup and look into building the application. 这就是Facebook发展起来的方式,以减少对环境设置的关注,并着眼于构建应用程序。 So, there's an easy way to create our project avoiding Webpack initiation. 因此,有一种简单的方法可以避免Webpack的启动来创建我们的项目。

Refer: https://www.techiediaries.com/react-tutorial/ 请参阅: https//www.techiediaries.com/react-tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM