KiRa
KiRa

Reputation: 924

Angular invalid configuration(Webpack)

I am learning angular for about a month. I am following a series of video that I've found in internet. I got stuck here in this error as shown in picture below.

Error

webpack.server.config.js code

const path = require('path');
const webpack = require('webpack');

module.exports = {
entry: { server: './server.ts' },
resolve: { extentions: ['.js', '.ts'] },
externals: [/{node_modules|main\..*\.js}/],
output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
},
module: {
    rules: {
        test: /\.ts$/,
        loader: 'ts-loader'
    }
},
plugins: [
    new webpack.ContextReplacementPlugin(
        /(.+)?angular(\\|\/)core(.+)?/,
        path.join(__dirname, 'src'),
        {}
    ),
    new webpack.ContextReplacementPlugin(
        /(.+)?express(\\|\/)(.+)?/,
        path.join(__dirname, 'src'),
        {}
    )
  ]
}

Package.json enter image description here

Upvotes: 0

Views: 46

Answers (1)

GregL
GregL

Reputation: 38103

The clues are right there in the error message. rules needs to be an array of objects, not a single object; and extensions is spelled with an s where you have a second t.

Here is the fixed version:

webpack.server.config.js code

const path = require('path');
const webpack = require('webpack');

module.exports = {
entry: { server: './server.ts' },
resolve: { extensions: ['.js', '.ts'] }, // CHANGED
externals: [/{node_modules|main\..*\.js}/],
output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
},
module: {
    rules: [{                           // CHANGED
        test: /\.ts$/,
        loader: 'ts-loader'
    }]                                  // CHANGED
},
plugins: [
    new webpack.ContextReplacementPlugin(
        /(.+)?angular(\\|\/)core(.+)?/,
        path.join(__dirname, 'src'),
        {}
    ),
    new webpack.ContextReplacementPlugin(
        /(.+)?express(\\|\/)(.+)?/,
        path.join(__dirname, 'src'),
        {}
    )
  ]
}

Upvotes: 1

Related Questions