我的 Webpack 配置出现错误:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
configuration.output.path
: The provided value"./"
is not an absolute path!
这是我的webpack.config.js
:
var config = {
entry: './main.js',
output: {
path:'./',
filename: 'index.js',
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
}
}
module.exports = config;
最佳答案
您的路径
必须是绝对的,而不是相对的。要使用当前目录,请使用变量 __dirname
:
__dirname
The directory name of the current module. This the same as the
path.dirname()
of the__filename
.
__dirname
is not actually a global but rather local to each module.Example: running
node example.js
from/Users/mjr
console.log(__dirname); // Prints: /Users/mjr console.log(path.dirname(__filename)); // Prints: /Users/mjr
因此,它是您当前的目录,配置以绝对路径形式存储在其中,您可以像这样应用它:
output: {
path: __dirname,
filename: 'index.js',
},
(请注意 ./
和 __dirname
之间存在差异,如 question 中所述。./
指当前目录调用脚本的终端的名称,__dirname
指的是脚本存储的目录。)
关于node.js - Webpack 配置不起作用,路径必须是绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125310/