serverless/serverless

Error: Cannot find module 'node:events'

Opened this issue · 3 comments

Issue description

I am seeing this issue in the aws codebuild container. I have serverless@3.18.0 and nodejs 12.20.0. It is very difficult for us to upgrade to nodejs 16. Is there any workaround for it? Tried downgrading simple-git 3.22.0 but no luck. Please help as it is very critical for us. I strongly believe it is something to do with simple-git package dependency. They have released version 12 days ago which is causing serverless to fail.

Error: Cannot find module 'node:events'

Require stack:

  • /usr/local/lib/node_modules/serverless/node_modules/simple-git/dist/cjs/index.js

  • /usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/deployment/parse.js

  • /usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/deployment/index.js

  • /usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/error-handler.js

  • /usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/plugin.js

  • /usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/index.js

  • /usr/local/lib/node_modules/serverless/lib/cli/handle-error.js

  • /usr/local/lib/node_modules/serverless/scripts/serverless.js

Context

I am still seeing this issue in aws codebuild container. I have serverless@3.18.0 and nodejs 12.20.0. It is very difficult for us to upgrade to nodejs 16. Is there any workaround on it? Tried downgrading simple-git 3.22.0 but no luck. Please help as it is very critical for us.

I have the exact same issue, using serverless 3.22 and node@12.

Upgrading node to 14 also requires an update of python version and it's not possible right now for us.

Hey @Bobby484
This is the exact root cause: serverless-framework uses @serverless/dashboard-plugin which internally uses simple-git.
However, in the package.json for dashboard-plugin, it installs simple-git with a carat. @^3.16, which means the latest version after 3.16, which is version 3.24

However, the format for importing like this node:events, is only supported from node14, hence the error.

I found a workaround for it. In my buildspec.yml after installing the serverless@3.22, I installed simple-git in it's node_modules directory.

 - current_dir=$(pwd)

 - npm install -g serverless@3.22.0
 
 - cd /usr/local/lib/node_modules/serverless
 
 - npm install simple-git@3.22.0
 
 - cd "$current_dir"

Thank you so much. worked like a charm.