未找到 Webpack 入口模块(按教程)
Webpack Entry module not found (by tutorial)
在 codeacademy 上找到 this tutorial(链接到最后一页),决定尝试这种部署和配置 js 应用程序的现代方式(决定尝试 ReactJS
)
按照说明逐步实施,但我发现了这个错误(当我尝试构建所有内容时)
ERROR in Entry module not found: Error: Can't resolve
'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' in
'C:\Users\temp1\Documents\Learn\ReactJS\playaround'
resolve 'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' in
'C:\Users\temp1\Documents\Learn\ReactJS\playaround'
using description file: C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json
(relative path: .)
Field 'browser' doesn't contain a valid alias configuration
after using description file: C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json
(relative path: .)
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html
doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.js
doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.json
doesn't exist
as directory
C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html
doesn't exist
我的 webpack.config.js
:
/** webpack required stuff */
var HTMLWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: __dirname + 'app/index.html',
filename: 'index.html',
inject: 'body',
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency'
});
/** thing which traces stuff and transforms in teh better way with babel(?) */
module.exports = {
entry: __dirname + '/app/index.js',
module:{
loaders:[
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
output:{
filename: 'transformed.js',
path: __dirname + '/build'
},
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true
},
plugins: [HTMLWebpackPluginConfig]
};
以及package.json
:
{
"name": "playaround",
"version": "1.0.0",
"description": "just test prj",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^2.29.0",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.6.1"
}
}
我不知道这里出了什么问题。怎么会?
看起来路径连接遗漏了一个斜杠,尝试
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: __dirname + '/app/index.html',
...
不过,可能更好的方法是像这样使用 path
实用程序模块 (https://nodejs.org/api/path.html):
const path = require('path')
...
template: path.join(__dirname, 'app', 'index.html')
...
这使得路径连接不易出错,并且 OS 独立(反斜杠与斜杠 windows 与基于 *nix 的 os)
在 codeacademy 上找到 this tutorial(链接到最后一页),决定尝试这种部署和配置 js 应用程序的现代方式(决定尝试 ReactJS
)
按照说明逐步实施,但我发现了这个错误(当我尝试构建所有内容时)
ERROR in Entry module not found: Error: Can't resolve 'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' in 'C:\Users\temp1\Documents\Learn\ReactJS\playaround' resolve 'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' in 'C:\Users\temp1\Documents\Learn\ReactJS\playaround' using description file: C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json (relative path: .) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json (relative path: .) No description file found no extension Field 'browser' doesn't contain a valid alias configuration C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html doesn't exist .js Field 'browser' doesn't contain a valid alias configuration C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.js doesn't exist .json Field 'browser' doesn't contain a valid alias configuration C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.json doesn't exist as directory C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html doesn't exist
我的 webpack.config.js
:
/** webpack required stuff */
var HTMLWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: __dirname + 'app/index.html',
filename: 'index.html',
inject: 'body',
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency'
});
/** thing which traces stuff and transforms in teh better way with babel(?) */
module.exports = {
entry: __dirname + '/app/index.js',
module:{
loaders:[
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
output:{
filename: 'transformed.js',
path: __dirname + '/build'
},
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true
},
plugins: [HTMLWebpackPluginConfig]
};
以及package.json
:
{
"name": "playaround",
"version": "1.0.0",
"description": "just test prj",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^2.29.0",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.6.1"
}
}
我不知道这里出了什么问题。怎么会?
看起来路径连接遗漏了一个斜杠,尝试
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: __dirname + '/app/index.html',
...
不过,可能更好的方法是像这样使用 path
实用程序模块 (https://nodejs.org/api/path.html):
const path = require('path')
...
template: path.join(__dirname, 'app', 'index.html')
...
这使得路径连接不易出错,并且 OS 独立(反斜杠与斜杠 windows 与基于 *nix 的 os)