我正在尝试修改从aws-nodejs-typescript
模板生成的代码。 我已经安装了typeorm
,reflect-metadata
和pg
以使用PostgreSQL。
它们在package.json
中的dependencies
里
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
可以工作,因此代码应该是正确的,问题在于未包含此软件包到zip压缩包中。
includeModules: true
,如何进行扩展? - Sergeycustom:{webpack:{webpackConfig:'./ webpack.config.js',includeModules:{forceInclude:["pg"]}},}
- Vishal Bareja