Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

webpack 打包 typescript nestjs项目, 打包之后的 main.js 无法运行?

我是个nodejs小菜鸡,在用nestjs写一个微服务架构的接口应用。我想通过webpack将这个项目打包为一个main.js文件。在github上找了一个脚手架 按照人家的方式配置,但是一样的配置放到我的项目里打包之后执行 node main.js 会抛出一个错误

throw new errors_1.CannotDetermineTypeError((_a = target.constructor) === null || _a === void 0 ? void 0 : _a.name, propertyKey);
        ^
CannotDetermineTypeError: Cannot determine a type for the "n.operation" field (union/intersection/ambiguous type was used). Make sure your property is decorated with a "@Prop({ type: TYPE_HERE })"

我的webpack配置是这样的:

const path = require('path');
const webpack = require('webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const { NODE_ENV = 'production' } = process.env;
console.log(`-- Webpack <${NODE_ENV}> build --`);
module.exports = {
  entry: './src/main.ts',
 mode: NODE_ENV,
 target: 'node',
 output: {
    path: path.resolve(__dirname, 'dist'),
 filename: 'main.js'
 },
 resolve: {
    extensions: ['.ts', '.js'],
 plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.build.json' })]
  },
 module: {
    rules: [
      {
        test: /.ts$/,
 use: ['ts-loader']
      }
    ]
  },
 stats: {
    warningsFilter: [
      'node_modules/express/lib/view.js',
     'node_modules/@nestjs/common/utils/load-package.util.js',
     'node_modules/@nestjs/core/helpers/load-adapter.js',
     'node_modules/mongoose/lib/index.js',
     'node_modules/mqtt/node_modules/ws/lib/buffer-util.js',
     'node_modules/mqtt/node_modules/ws/lib/validation.js',
     'node_modules/mongodb/lib/operations/connect.js',
     'node_modules/grpc/src/grpc_extension.js',
     'node_modules/bytebuffer/dist/bytebuffer-node.js',
     'node_modules/@nestjs/core/helpers/optional-require.js',
     'node_modules/require_optional/index.js',
     'node_modules/node-pre-gyp/lib/util/versioning.js',
     'node_modules/node-pre-gyp/lib/pre-binding.js',
     'node_modules/ws/lib/buffer-util.js',
     'node_modules/ws/lib/validation.js',
     warning => false
     ]
      }
    };

请各位大佬帮小弟看看,这到底是个啥问题。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...