找不到模块 'html-webpack-plugin'(初学者)
Cannot find module 'html-webpack-plugin' (beginner)
我正在做一个我应该在在线课程中做的小项目。
我已经下载了必要的模块。然后我应该在命令行中 运行 (npm 运行 start),但我一直收到此错误“找不到模块 'html-webpack-plugin'”.. 将感谢您的帮助。我已经在这里阅读了所有其他线程,但刻痕似乎有帮助。
我应该创建一个简单的 Html 副本或在实时服务器中显示的东西...我已尝试重新安装所有内容并安装 -g、--save-dev 或只是 - 救球。必要的包在 node-modules 文件夹中
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/bundle.js'
},
devServer: {
contentBase: './dist'
},
plugins: [
new HtmlWebpackPlugin({
filename: './dist/index.html',
template: './src/index.html',
})
]
};
package.json
{
"name": "forkify",
"version": "1.0.0",
"description": "forkify project",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "Kushtrim",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
"install": "^0.13.0",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.8",
"webpack-dev-server": "^3.8.0"
},
"dependencies": {}
}
$npm 运行 开始
> forkify@1.0.0 start C:\Users\mrB\Documents\Web-development\complete-
javascript-course-master-forkify\starter
> webpack-dev-server --mode development --open
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'html-webpack-plugin'
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:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\mrB\Documents\Web-development\complete-
javascript-course-master-forkify\webpack.config.js:2:27)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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! forkify@1.0.0 start: `webpack-dev-server --mode development --
open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the forkify@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\mrB\AppData\Roaming\npm-cache\_logs19-09-
13T10_42_46_932Z-debug.log
应该发生的是 webpack-dev-server 应该启动。但是我所做的一切似乎都无济于事。
看来你需要先安装所有的依赖。
尝试
npm install
然后
npm run start
我正在做一个我应该在在线课程中做的小项目。 我已经下载了必要的模块。然后我应该在命令行中 运行 (npm 运行 start),但我一直收到此错误“找不到模块 'html-webpack-plugin'”.. 将感谢您的帮助。我已经在这里阅读了所有其他线程,但刻痕似乎有帮助。
我应该创建一个简单的 Html 副本或在实时服务器中显示的东西...我已尝试重新安装所有内容并安装 -g、--save-dev 或只是 - 救球。必要的包在 node-modules 文件夹中
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/bundle.js'
},
devServer: {
contentBase: './dist'
},
plugins: [
new HtmlWebpackPlugin({
filename: './dist/index.html',
template: './src/index.html',
})
]
};
package.json
{
"name": "forkify",
"version": "1.0.0",
"description": "forkify project",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "Kushtrim",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
"install": "^0.13.0",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.8",
"webpack-dev-server": "^3.8.0"
},
"dependencies": {}
}
$npm 运行 开始
> forkify@1.0.0 start C:\Users\mrB\Documents\Web-development\complete-
javascript-course-master-forkify\starter
> webpack-dev-server --mode development --open
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'html-webpack-plugin'
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:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\mrB\Documents\Web-development\complete-
javascript-course-master-forkify\webpack.config.js:2:27)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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! forkify@1.0.0 start: `webpack-dev-server --mode development --
open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the forkify@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\mrB\AppData\Roaming\npm-cache\_logs19-09-
13T10_42_46_932Z-debug.log
应该发生的是 webpack-dev-server 应该启动。但是我所做的一切似乎都无济于事。
看来你需要先安装所有的依赖。
尝试
npm install
然后
npm run start