Dimitri van Hees
05/11/2022, 2:15 PMnode v14.19.1
with npm 8.9.0
. Following https://serverless-stack.com/examples/how-to-use-lambda-layers-in-your-serverless-app.html, it throws the error
Cannot find module '/home/dev/layer-chrome-aws-lambda/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser'.
This is, by the way, after fixing the Cannot find a handler file for "lambda.handler"
error by moving backend/functions/lambda.ts
to backend/lambda.ts
(I think the tutorial outdated the new directory structure).
Removing the bundle: { externalModules: ["chrome-aws-lambda"] },
line results in another error:
ReferenceError: __dirname is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/home/dev/layer-chrome-aws-lambda/.sst/artifacts/dev-layer-chrome-aws-lambda-MyStack-Api-Lambda_GET_-/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
I've tried multiple workarounds (including downgrading node and npm versions but that caused a lot of other issues) but none seem to work. Any thoughts?
Below are the dependencies of my `package.json`:
{
"devDependencies": {
"@serverless-stack/cli": "^1.0.4",
"@serverless-stack/resources": "^1.0.4",
"@tsconfig/node14": "^1.0.1",
"typescript": "^4.6.4"
},
"workspaces": [
"backend"
],
"dependencies": {
"chrome-aws-lambda": "^10.1.0",
"puppeteer": "^14.0.0",
"puppeteer-core": "^14.0.0"
}
}
manitej
05/11/2022, 2:20 PMmanitej
05/11/2022, 2:23 PMbackend/
folder and check if it works.
npm install puppeteer puppeteer-core chrome-aws-lambda
Dimitri van Hees
05/11/2022, 2:29 PMmanitej
05/11/2022, 2:30 PM