[英]Error in Entry Module not found - in Webpack Config file
I am trying to setup webpack for ReactJs. 我正在尝试为ReactJs设置webpack。 I am clueless what is wrong with my Webpack Config File which gives me
我无法解释我的Webpack配置文件出了什么问题
ERROR in Entry module not found: Error: Can't resolve './src' in 'D:\\wd\\javascript\\Projects\\reactjs-basics
找不到Entry模块中的错误:错误:无法解析'D:\\ wd \\ javascript \\ Projects \\ reactjs-basics中的'./src'
CODE IS HERE - Two files "Webpack.config.js " and "Package.json" 代码在这里 - 两个文件“Webpack.config.js”和“Package.json”
Webpack.config.js code is :
Webpack.config.js代码是:
var webpack = require('webpack');
var path = require('path');
var DIST_DIR = path.resolve(__dirname,'dist');
var SRC_DIR = path.resolve(__dirname,'src');
var config = {
entry: SRC_DIR+'/app/index.js',
output:{
path:DIST_DIR+'/app',
filename:'bundle.js',
publicPath:'/app/'
},
module:{
rules: [
{
test: /\.js?/,
include: SRC_DIR,
use:{
loader:'babel-loader',
query:{
presets:['react','es2015','stage-2']
}
}
}
]
},
mode: 'development',
watch: true
}
module.export = config;
Package.json File is
Package.json文件是
{
"name": "reactjs-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": " npm run build",
"build": "webpack -d && copy src\\app/index.html dist\\index.html && webpack-dev-server --content-base src\\ --inline --hot",
"build:prod": "webpack -p && cp src\\app/index.html dist\\index.html"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"devDependencies": {
"2015": "0.0.1",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.5",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1"
}
}
** **
for reference, Folder Structure with Webpack config code i have attache an image below
作为参考,文件夹结构与Webpack配置代码我附上一个图像
** **
Please Click here for folder structure, code and folder structure is juxtaposed 请点击此处查看文件夹结构,代码和文件夹结构并列
You've to modify few things 你要修改一些东西
webpack.config.js
you have module.export
. webpack.config.js
你有module.export
。 This is incorrect. module.exports
module.exports
babel-core@6.26.3
with babel-loader@8.0.5
. babel-core@6.26.3
和babel-loader@8.0.5
。 babel-loader@8.*
is not compatible with babel-core@6.*
. babel-loader@8.*
与babel-core@6.*
不兼容。 You've to use babel-loader@7
. babel-loader@7
。 Uninstall your existing babel-loader
using npm uninstall -D babel-loader
and install babel-loader@7
using npm install -D babel-loader@7
babel-loader
使用npm uninstall -D babel-loader
和安装babel-loader@7
使用npm install -D babel-loader@7
Another thing i noted is, you have specified mode: 'development'
in your webpack.config.js
. 我注意到的另一件事是,你在
webpack.config.js
指定了mode: 'development'
。 its better to set mode to development or production
via runtime parameters 最好通过运行时参数将
mode to development or production
设置mode to development or production
Update 更新
Remove mode
& watch
from your webpack.config.js
从
webpack.config.js
删除mode
并watch
mode: 'development',
watch: true
Update your package.json
with below details. 使用以下详细信息更新您的
package.json
。
Development mode You don't need to set watch
& mode
as webpack-dev-server
will do that for you when you run npm run dev
开发模式您不需要设置
watch
和mode
因为webpack-dev-server
将在您运行npm run dev
时为您执行此操作
"scripts": {
"webpack": "webpack",
"dev": "mkdir -p dist && cp ./src/index.html dist/index.html && webpack-dev-server",
"prod": "mkdir -p dist && cp ./src/index.html dist/index.html && npm run webpack -- --mode production"
}
To launch local server
you need to add below configuration in your webpack.config.js
. 要启动
local server
您需要在webpack.config.js
添加以下配置。 Note the directory name
to which the devserver
points to. 请注意
devserver
指向的directory name
。
devServer: {
contentBase: path.join(__dirname, "dist/"),
port: 9000
},
Production mode Execute npm run prod
to build your project in production mode 生产模式执行
npm run prod
以生产模式构建项目
You can see localhost in working state when your run npm run dev
.This server is launched by webpack-dev-server
library. 运行
npm run dev
时,您可以看到localhost处于工作状态。此服务器由webpack-dev-server
库启动。 For production build
you have to configure your own server 对于
production build
您必须配置自己的服务器
Let me know if this helps 如果这有帮助,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.