Reputation: 7737
/node_modules/webpack/lib/TemplatedPathPlugin.js:72
.replace(REGEXP_HASH, withHashLength(getReplacer(data.hash), data.hashWithLength))
^
I'm getting this error when running webpack
- it seems that path
is an object rather than a string, and the replace method is therefore not found. Can anyone shed light on this error? Here's my webpack.config.js
:
var webpack = require('webpack');
var path = require('path');
var basePath = 'app';
var outputFile = 'output.js';
var config = {
entry: basePath + '/index.js',
output: {
path: basePath,
filename: outputFile
},
resolve: {
extensions: ['', '.js']
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}]
}
};
module.exports = config;
Upvotes: 4
Views: 14893
Reputation: 173
Check your plugin configuration. Webpack 2 changes the ExtractTextPlugin slightly. It expects all parameters to come wrapped in an object, so your first parameter is now the value of filename
on that object rather than a string.
Webpack 1 way:
new ExtractTextPlugin('[hash].css', {allChunks: true, disable: false}),
Webpack 2 way:
new ExtractTextPlugin({filename: '[hash].css', allChunks: true, disable: false}),
More info in the README
Upvotes: 11
Reputation: 1044
The easiest way to track down the issue is by giving console.log(path)
on file /node_modules/webpack/lib/TemplatedPathPlugin.js
.
I got same error recently -- then I went to that file and modify the replacePathVariables
function:
function replacePathVariables(path, data) {
console.log(' ---> ', path)
var chunk = data.chunk;
var chunkId = chunk && chunk.id;
I found out that I was accidentally set output.publicPath
option with array:
output: {
publicPath: ['/dist/']
}
Instead of (string):
output: {
publicPath: '/dist/'
}
Upvotes: 1