Javascript Webpack 中未配置输出文件名错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34157313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Output filename not configured Error in Webpack
提问by anandharshan
I had installed it globally by running npm install webpack -g and I had included it in my project by running npm install webpack --save-dev.
我通过运行 npm install webpack -g 全局安装了它,并通过运行 npm install webpack --save-dev 将它包含在我的项目中。
However, on running the webpack command, I was seeing the following output: Output filename not configured.
但是,在运行 webpack 命令时,我看到了以下输出:未配置输出文件名。
This is the webpack config:
这是 webpack 配置:
output: {
filename: 'bundle.js',
library: 'require',
libraryTarget: 'this'
},
This is the only clue i could get from the web :: http://anujnair.com/blog/12-output-filename-not-configured-error-from-webpackBut it did not solve the issue
这是我从网上能得到的唯一线索 :: http://anujnair.com/blog/12-output-filename-not-configured-error-from-webpack但它没有解决问题
Any Help will be great
任何帮助都会很棒
回答by spiffysparrow
I was getting the same error and it turned out to be my webpack config file name.
我遇到了同样的错误,结果是我的 webpack 配置文件名。
I had it as "webpack.config
" instead of "webpack.config.js
"
我把它当作“ webpack.config
”而不是“ webpack.config.js
”
The "Output filename not configured" error seems to come up generally when there is a typo somewhere, and I've found the file name to be a sneaky place you forget to check.
“输出文件名未配置”错误似乎通常在某处有拼写错误时出现,我发现文件名是您忘记检查的偷偷摸摸的地方。
回答by bigtex777
Also double-check that the webpack.config.js
file is in the right spot (in general, the root directory of the project) and the paths listed in the config file are correct.
还要仔细检查webpack.config.js
文件是否在正确的位置(通常是项目的根目录)以及配置文件中列出的路径是否正确。
回答by Sudeep K Rana
Common mistakes of this error is typo and most of the times it's writing
module.export
instead of module.exports
.
Also check the file name should be with a .js extension. e.g. webpack.config.js
此错误的常见错误是拼写错误,并且大多数情况下它正在编写
module.export
而不是module.exports
. 还要检查文件名是否应该带有 .js 扩展名。例如webpack.config.js
回答by Tiago Gouvêa
You MUST have a file named webpack.config.js
on project root.
您必须有一个以webpack.config.js
项目根目录命名的文件。
回答by meij
You have a typo somewhere in your webpack.config.js
file. Review your config file. Had similar problem and it was as a result of a typo.
您的webpack.config.js
文件中某处有拼写错误。查看您的配置文件。有类似的问题,这是由于打字错误造成的。
回答by theterminalguy
Try exporting your configuration using module.exports = config
where config is your configuration in a JavaScript object. In your case just do
尝试使用module.exports = config
config 是 JavaScript 对象中的配置导出您的配置。在你的情况下就做
module.exports = {
output: {
filename: 'bundle.js',
library: 'require',
libraryTarget: 'this'
}
}
If this does not solve your problems, refer to the issue on https://github.com/webpack/webpack/issues/2403
如果这不能解决您的问题,请参阅https://github.com/webpack/webpack/issues/2403上的问题
回答by strausd
I ran into this problem after following Webpacks docs for production builds. The way I ran into the issue is, I believe, specific to webpack-merge.
在遵循用于生产构建的 Webpacks 文档后,我遇到了这个问题。我遇到这个问题的方式是,我相信,特定于 webpack-merge。
This is what their docs have in webpack.dev.js:
这是他们的文档在 webpack.dev.js 中的内容:
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
}
});
But this is what I needed to have:
但这是我需要的:
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common(), {
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
}
});
Notice the only change is running common()
instead of common
.
请注意,唯一的变化是 runningcommon()
而不是common
.
回答by Nicholas Murray
This error will also occur if you are running the command 'webpack -w' against a directory that does not have a webpack config file.
如果您对没有 webpack 配置文件的目录运行命令“webpack -w”,也会发生此错误。
So if you are opening a new terminal window or tab and haven't changed directory to the root of your project before running the webpack command you will receive the error.
因此,如果您打开一个新的终端窗口或选项卡,并且在运行 webpack 命令之前没有将目录更改为项目的根目录,您将收到错误消息。
回答by betmakh
If you using __dirname
make sure it referenced to correct path. Default path is /
which is local drive root.
如果您使用__dirname
确保它引用了正确的路径。默认路径是/
本地驱动器根目录。
回答by Imir Hoxha
just to post my solution. Might help someone.
只是为了发布我的解决方案。可能会帮助某人。
if you get this error, it always has to do with some typo error. In my case I had forgotten to close the last }
with a semicolon at the end, like this: };
如果你得到这个错误,它总是与一些拼写错误有关。就我而言,我忘记在最后}
用分号关闭最后一个,如下所示:};
module.exports = {
entry: './index.js',
output: {
filename:'bundle.js'
}
};
This worked.
这奏效了。