webpack - 错误:找不到模块'webpack/lib/node/NodeTemplatePlugin'
Posted
技术标签:
【中文标题】webpack - 错误:找不到模块\'webpack/lib/node/NodeTemplatePlugin\'【英文标题】:web pack - Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'webpack - 错误:找不到模块'webpack/lib/node/NodeTemplatePlugin' 【发布时间】:2020-09-14 07:30:27 【问题描述】:我在执行 npm run dev
时遇到此错误,并且我已在我的电脑中全局安装了最新的 react/react-dom 并在此项目中本地安装。
可以做些什么来解决这个问题?
macbookpro@MacBookProdeMacBook-Pro 01.webpack-base % npm run dev
> 01.webpack-base@1.0.0 dev /Users/macbookpro/Desktop/01.webpack-base
> webpack-dev-server --open
internal/modules/cjs/loader.js:985
throw err;
^
Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Require stack:
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/cached-child-compiler.js
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/index.js
- /Users/macbookpro/Desktop/01.webpack-base/webpack.config.js
- /usr/local/lib/node_modules/webpack-cli/bin/utils/convert-argv.js
- /usr/local/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js:14:28)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js',
'/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/cached-child-compiler.js',
'/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/index.js',
'/Users/macbookpro/Desktop/01.webpack-base/webpack.config.js',
'/usr/local/lib/node_modules/webpack-cli/bin/utils/convert-argv.js',
'/usr/local/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 01.webpack-base@1.0.0 dev: `webpack-dev-server --open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 01.webpack-base@1.0.0 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/macbookpro/.npm/_logs/2020-05-27T09_15_12_766Z-debug.log
【问题讨论】:
这能回答你的问题吗? Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' 【参考方案1】:我遇到了类似的问题,下面帮助我解决了这个问题
rm -rf node_modules
rm package-lock.json
npm cache verify
npm install
如果它不起作用,可以试试这个取自Raunaqss's answer:
从 Webpack 4 开始,您需要安装 webpack-cli。如果您需要使用此页面上标有键的选项,您可能还需要安装 webpack-dev-middleware。
在这种情况下,要安装的命令是:
npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware
如上所述,webpack-dev-middleware 应根据您的要求选择性添加。
【讨论】:
以上是关于webpack - 错误:找不到模块'webpack/lib/node/NodeTemplatePlugin'的主要内容,如果未能解决你的问题,请参考以下文章
错误:找不到模块 'webpack/lib/rules/DescriptionDataMatcherRulePlugin' 需要堆栈:
找不到模块:错误:无法解析模块“组件/应用程序”。 webpack + reactjs 问题