package.json does not exist at /package.json
When I am trying to use webpack in order to build my project and use it on AWS Lambda, I am getting a lot of warnings related to Critical dependency of ./node_modules/grpc. This issue happening once I import {GoogleAdsApi} from 'google-ads-api';
As I can understand this is related to dynamic importing, I might be wrong. As a result, the bundled file is huge (above 4MB) and when zipping it and using it on the Lambda I am getting the following error when the Lambda is triggered: "package.json does not exist at /package.json"
*Typescript
*Node ver 12.x
index.ts
import {GoogleAdsApi} from 'google-ads-api'; export const handler = async (event: any): Promise<any> => { try { console.log('Start', event); // @ts-ignore const api = new GoogleAdsApi({client_id: 'id', client_secret: 'secret', developer_token: 'dToken'}); return 'success'; } catch (e) { console.log('Error', e); throw e; } };
Error: package.json does not exist at /package.json, at Object.exports.find (/var/task/webpack:/node_modules/node-pre-gyp/lib/pre-binding.js:18:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/grpc_extension.js:29:1), at Object.<anonymous> (/var/task/index.js:40079:30), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client_interceptors.js:144:12), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client.js:35:27), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/index.js:27:14), at Object.<anonymous> (/var/task/index.js:2460:30)
Webpack Warnings Webpack Warnings:
WARNING in ./node_modules/bytebuffer/dist/bytebuffer-node.js 29:38-55 Module not found: Error: Can't resolve 'memcpy' in WARNING in ./node_modules/google-ads-node/node_modules/import-fresh/index.js 28:8-25 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/grpc/src/grpc_extension.js 32:12-33 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67 Critical dependency: the request of a dependency is an expression
webpack.config.js:
`const path = require("path") const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin") module.exports = { mode: "production", entry: "./src/index.ts", resolve: { extensions: [".js", ".jsx", ".json", ".ts", ".tsx"], }, output: { libraryTarget: "commonjs", path: path.join(__dirname, "dist"), filename: "index.js", }, target: "node", module: { rules: [ { // Include ts, tsx, js, and jsx files. test: /.(ts|js)x?$/, exclude: /node_modules/, use: [ { loader: "cache-loader", options: { cacheDirectory: path.resolve(".webpackCache"), }, }, "babel-loader", ], }, ], }, plugins: [new ForkTsCheckerWebpackPlugin()], }`