找不到模块'webpack' - Angular
问题描述:
我刚刚将我的项目从 angular v5.x 迁移到 v6.x,现在当我尝试使用 ng serve
启动它时,我得到:
I just migrated my project from angular v5.x to v6.x and now when I try to start it with ng serve
I'm getting:
Cannot find module 'webpack'
Error: Cannot find module 'webpack'
at Function.Module....
有什么帮助吗?
我清除了节点模块并:
npm 缓存清理 --force
npm install
npm install --save-dev @angular/cli@latest
但这没有帮助
答
我遇到了同样的问题,这对我有用:
I had the same issue and this worked for me:
删除这些文件/文件夹(从您的 Angular 根文件夹中):
Delete these files/ folders (from your Angular root folder):
-
package-lock.json
(不是 package.json) -
/node_modules
文件夹 -
/dist
文件夹
-
package-lock.json
(Not the package.json) -
/node_modules
folder -
/dist
folder
执行命令(重新生成package-lock.json
和/node_modules
):
Execute command (regenerate the package-lock.json
and the /node_modules
):
-
$npm install
现在一切正常,是 package-lock.json
导致 npm 下载旧版本的依赖项.
Everything should work now, it was the package-lock.json
that caused npm to download old versions of dependencies.