Angular 无效配置(Webpack) [英] Angular invalid configuration(Webpack)

查看:37
本文介绍了Angular 无效配置(Webpack)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习 angular 大约一个月了.我正在关注我在互联网上找到的一系列视频.我陷入了这个错误,如下图所示.

webpack.server.config.js 代码

const path = require('path');const webpack = require('webpack');模块.出口 = {条目:{服务器:'./server.ts'},解决:{扩展名:['.js','.ts']},外部:[/{node_modules|main\..*\.js}/],输出: {路径:path.join(__dirname, 'dist'),文件名:'[名称].js'},模块: {规则:{测试:/\.ts$/,装载机:'ts-装载机'}},插件: [新的 webpack.ContextReplacementPlugin(/(.+)?angular(\\|\/)core(.+)?/,path.join(__dirname, 'src'),{}),新的 webpack.ContextReplacementPlugin(/(.+)?express(\\|\/)(.+)?/,path.join(__dirname, 'src'),{})]}

<块引用>

Package.json

解决方案

线索就在错误消息中.rules 需要是一个对象数组,而不是单个对象;并且 extensions 拼写为 s,其中您有第二个 t.

这是固定版本:

webpack.server.config.js 代码

const path = require('path');const webpack = require('webpack');模块.出口 = {条目:{服务器:'./server.ts'},解析:{ 扩展名:['.js', '.ts'] },//已更改外部:[/{node_modules|main\..*\.js}/],输出: {路径:path.join(__dirname, 'dist'),文件名:'[名称].js'},模块: {规则:[{//已更改测试:/\.ts$/,装载机:'ts-装载机'}]//改变了},插件: [新的 webpack.ContextReplacementPlugin(/(.+)?angular(\\|\/)core(.+)?/,path.join(__dirname, 'src'),{}),新的 webpack.ContextReplacementPlugin(/(.+)?express(\\|\/)(.+)?/,path.join(__dirname, 'src'),{})]}

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.

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

解决方案

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'),
        {}
    )
  ]
}

这篇关于Angular 无效配置(Webpack)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆