获取“找不到模块”错误

时间:2017-09-11 06:26:12

标签: node.js angular webpack

当我使用

运行我的角度2项目时
  

npm start

我有这样的错误。我在我的项目中使用webpack。这是我的Webpack

const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
    entry: {
        server: './src/server.ts'
    },
    resolve: {
        extensions: ['.ts', '.js']
    },
    target: 'node',    
    plugins: [
    new webpack.NormalModuleReplacementPlugin(/\.\.\/environments\/environment/, '../environments/environment.prod')
    ],
    externals: [nodeExternals({
        whitelist: [
        /^ng2-timeout/
        ]
    })],
    node: {
        __dirname: true
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].js'
    },
    module: {
        rules: [
        { test: /\.ts$/, loader: 'ts-loader' }
        ]
    }
}

在运行我的项目时,我有这样的错误 Error

1 个答案:

答案 0 :(得分:0)

通过从webpack文件中删除此代码来解决此问题

 plugins: [
    new webpack.NormalModuleReplacementPlugin(/\.\.\/environments\/environment/, '../environments/environment.prod')
    ],