gpt4 book ai didi

javascript - 找不到模块 'html-webpack-plugin'(初学者)

转载 作者:行者123 更新时间:2023-11-30 06:12:46 24 4
gpt4 key购买 nike

我正在做一个我应该在在线类(class)中做的小项目。我已经下载了必要的模块。然后我应该在命令行中运行 (npm run start),但我不断收到此错误“无法找到模块‘html-webpack-plugin’”.. 将感谢您的帮助。我已经在这里阅读了所有其他线程,但刻痕似乎有帮助。

我应该创建一个简单的 Html 副本或要在实时服务器中显示的内容...我已尝试重新安装所有内容并安装 -g、--save-dev 或只是 --save。必要的包在节点模块文件夹中

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\9-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\9-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\_logs\2019-09-
13T10_42_46_932Z-debug.log

应该发生的是 webpack-dev-server 应该启动。但我所做的一切似乎都无济于事。

最佳答案

看来你需要先安装所有的依赖

尝试

npm install

然后

npm run start

关于javascript - 找不到模块 'html-webpack-plugin'(初学者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57922637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com