尝试使用 webpack 构建时多 ./src ./build/中的错误 [英] ERROR in multi ./src ./build/ when trying to build with webpack
问题描述
我在构建 webpack 3.8.1 时遇到一个奇怪的错误:
I'm getting a strange error with webpack 3.8.1 when I build:
ERROR in multi ./src ./build/
Module not found: Error: Can't resolve '/Users/me/files/project/build/' in '/Users/me/files/project'
@ multi ./src ./build/
如果我升级到 webpack 3.11.0:
And if I upgrade to webpack 3.11.0:
未找到输入模块中的错误:错误:无法解析/Users/me/files/project"中的/Users/me/files/project/build/"
ERROR in Entry module not found: Error: Can't resolve '/Users/me/files/project/build/' in '/Users/me/files/project'
我的项目似乎正在构建中,但它不断记录此错误.在开发服务器上一切正常.https://github.com/webpack/webpack/issues/981 或 Webpack 错误 - 无法解析文件或目录 有帮助.
My project seems to be getting built, but it keeps logging this error. Everything works fine with the devserver. None of the solutions in https://github.com/webpack/webpack/issues/981 or Webpack Error - Cannot Resolve File or Directory are helping.
推荐答案
问题是我自己的错.我试图使用 webpack build
命令"构建我的应用程序,这根本不是命令!相反,webpack 认为我正在尝试构建一些称为构建"的东西.
The issue was my own fault. I was trying to build my app using the webpack build
"command", which is not a command at all! Instead webpack thought I was trying to build something called "build".
构建 webpack 的正确用法很简单
The correct usage to get webpack to build is simply
webpack
没有子命令或附加路径.
with no subcommands or additional paths.
通过一个示例项目,我确实设置了一个 npm build
脚本,这可能是我记得的命令.但是这个快捷方式"在我的 package.json 中定义为简单的 "scripts":{"build": "webpack"}
.两种方式都可以正常工作,不会出现意外错误,但将两者混用会导致麻烦.
Via a sample project I did have an npm build
script set up, and that might have been the command I was remembering. But that "shortcut" is defined in my package.json as simply "scripts":{"build": "webpack"}
. Both ways work without the unexpected error, but mixing up the two will cause trouble.
这篇关于尝试使用 webpack 构建时多 ./src ./build/中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!