What went wrong?
When used with typeorm.js or squelize.js and deploy, ERROR in src/server.js from UglifyJs occured.
What did you expect should have happened?
Successful deployment. Because when i tried to "ts-node src/server.ts", it's worked. and deleted code related to typeorm(or sequelize.js), it dosen't work.
What was the config you used?
I used "serverless create --template aws-nodejs-typescript" and runtime environment is node 8,
webpack.config.js
const path = require('path');
const slsw = require('serverless-webpack');
const entries = {};
Object.keys(slsw.lib.entries).forEach(
(key) => (entries[key] = [ './source-map-install.js', slsw.lib.entries[key] ])
);
module.exports = {
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: entries,
devtool: 'source-map',
resolve: {
extensions: [ '.js', '.jsx', '.json', '.ts', '.tsx' ]
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
target: 'node',
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' }
]
}
};
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "./dist",
"target": "es2015",
"lib": [
"esnext"
],
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}
ERROR in src/server.js from UglifyJs
undefined
@wooooooak This looks quite strange. I assume the error occurs when executing the compiled code in the lambda environment?
Can you give me the webpack version you used?
To investigate further, you could try to disable minification (uglify) in your webpack config like this:
// webpack.config.js
module.exports = {
...
optimization: {
// We do not want to minimize our code.
minimize: false
},
...
};
@HyperBrain
I used webpack version 4.5.0. And by disabling to minimize it's work :D
Thank you for your quick feedback. but i don't know why uglify didn't works.
@wooooooak The only idea I have is, that uglify has a problem with TypeScript and tsc somehow.
I think I hit this at one point. TypeORM uses reflection to generate a database schema from the structure of the entity classes - this doesn't play nice with Uglify as it mangles the property names.
@SebastianEdwards Thanks for the info. Maybe the solution would be to tell users to disable minfication for TS projects and change the serverless typescript template accordingly in the serverless project.
Most helpful comment
@SebastianEdwards Thanks for the info. Maybe the solution would be to tell users to disable minfication for TS projects and change the serverless typescript template accordingly in the serverless project.