【发布时间】:2021-07-08 06:17:19
【问题描述】:
我正在尝试修改从aws-nodejs-typescript 模板生成的代码。我已经安装了 typeorm、reflect-metadata 和 pg 来使用 PostgreSQL。
webpack 配置是默认配置
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
/*
This line is only required if you are specifying `TS_NODE_PROJECT` for whatever reason.
*/
// delete process.env.TS_NODE_PROJECT;
module.exports = {
context: __dirname,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map',
resolve: {
extensions: ['.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
plugins: [
new TsconfigPathsPlugin({
configFile: './tsconfig.paths.json',
}),
],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
optimization: {
concatenateModules: false,
},
target: 'node',
externals: [nodeExternals()],
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.(tsx?)$/,
loader: 'ts-loader',
exclude: [
[
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '.serverless'),
path.resolve(__dirname, '.webpack'),
],
],
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
plugins: [],
};
问题:在sls deploy 之后,zip 存档不包含pg 包,因此请求失败为Postgres package has not been found installed. Try to install it: npm install pg --save。我该如何解决这个问题?
我怀疑这可能是因为动态依赖解析或其他原因,因为我的代码中没有直接依赖,typeorm 根据连接配置中的字符串决定使用哪个驱动程序。
附: sls offline 有效,因此代码应该是正确的,问题在于这个未包含的压缩包压缩包。
【问题讨论】:
标签: node.js typescript webpack typeorm serverless