成功解决Error: Cannot find module 'html‐webpack‐plugin'

我的webpack.config.js

var htmlwp = require('html‐webpack‐plugin');
module.exports={
    entry:'./src/main.js', //指定打包的入口文件
    output:{
        path : __dirname+'/dist', // 注意:__dirname表示webpack.config.js所在目录的绝对路径
        filename:'build.js' //输出文件
    },
    plugins:[
        new htmlwp({
            title: '首页', //生成的页面标题<head><title>首页</title></head>
            filename: 'index.html', //webpack‐dev‐server在内存中生成的文件名称,自动将build注入到这 个页面底部,才能实现自动刷新功能
            template: 'vue_02.html' //根据index1.html这个模板来生成(这个文件请程序员自己生成)
        })
    ]
}

打包的时候出报下面的错

/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run dev --scripts-prepend-node-path=auto

> @ dev /Users/lixinyu/myspace/xcEduUI01/xc-ui-pc-static-portal/webpacktest02
> webpack-dev-server --inline --hot --open --port 5008

module.js:557
    throw err;
    ^

Error: Cannot find module 'htmlwebpack‐plugin'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/lixinyu/myspace/xcEduUI01/xc-ui-pc-static-portal/webpacktest02/webpack.config.js:1:76)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `webpack-dev-server --inline --hot --open --port 5008`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ 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!     /Users/lixinyu/.npm/_logs/2019-05-11T07_45_49_325Z-debug.log

Process finished with exit code 1

原因是因为webpack.config.js是从pdf中复制过来的, 所以字体不对, 删除后从新输入, 问题解决

猜你喜欢

转载自blog.csdn.net/weixin_39973810/article/details/90110643