TypeError: path.replace is not a function

/node_modules/webpack/lib/TemplatedPathPlugin.js:72
        .replace(REGEXP_HASH, withHashLength(getReplacer(data.hash), data.hashWithLength))
         ^

I get this error on startup webpack- it seems to be pathan object, not a string, so the replace method was not found. Can anyone shed some light on this mistake? Here's mine 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;
+4
source share
2 answers

Check plugin configuration. Webpack 2 slightly modifies ExtractTextPlugin. He expects that all parameters will be transferred to the object, so your first parameter will now be the value filenamefor this object, and not for the string.

Webpack 1 way: new ExtractTextPlugin('[hash].css', {allChunks: true, disable: false}),

Webpack 2 way: new ExtractTextPlugin({filename: '[hash].css', allChunks: true, disable: false}),

Additional information in README

+11
source

- console.log(path) /node_modules/webpack/lib/TemplatedPathPlugin.js.

- replacePathVariables:

function replacePathVariables(path, data) { console.log(' ---> ', path) var chunk = data.chunk; var chunkId = chunk && chunk.id;

, output.publicPath :

output: { publicPath: ['/dist/'] }

(string):

output: { publicPath: '/dist/' }

0

Source: https://habr.com/ru/post/1655493/


All Articles