Cannot find module 'ajv/dist/compile/codegen'
See original GitHub issueNot sure if this is something that just can’t be helped, but it seems that if a NodeJS project has a dependency on ajv^6
it’ll cause the packaging step to fail. I believe this was caused by the bump to ajv^7
. I know that many projects still depend on the earlier version, so it might break a lot of projects.
Steps to reproduce:
- Create a new project using
sls init
- Select NodeJS project
- Install
ajv^6
vianpm i ajv@^6
- Execute
sls package
serverless.yml
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: test
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
# you can overwrite defaults here
# stage: dev
# region: us-east-1
# you can add statements to the Lambda function's IAM Role here
# iamRoleStatements:
# - Effect: "Allow"
# Action:
# - "s3:ListBucket"
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
# - Effect: "Allow"
# Action:
# - "s3:PutObject"
# Resource:
# Fn::Join:
# - ""
# - - "arn:aws:s3:::"
# - "Ref" : "ServerlessDeploymentBucket"
# - "/*"
# you can define service wide environment variables here
# environment:
# variable1: value1
# you can add packaging information here
#package:
# include:
# - include-me.js
# - include-me-dir/**
# exclude:
# - exclude-me.js
# - exclude-me-dir/**
functions:
hello:
handler: handler.hello
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# - http:
# path: users/create
# method: get
# - websocket: $connect
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
# - iot:
# sql: "SELECT * FROM 'some_topic'"
# - cloudwatchEvent:
# event:
# source:
# - "aws.ec2"
# detail-type:
# - "EC2 Instance State-change Notification"
# detail:
# state:
# - pending
# - cloudwatchLog: '/aws/lambda/hello'
# - cognitoUserPool:
# pool: MyUserPool
# trigger: PreSignUp
# - alb:
# listenerArn: arn:aws:elasticloadbalancing:us-east-1:XXXXXX:listener/app/my-load-balancer/50dc6c495c0c9188/
# priority: 1
# conditions:
# host: example.com
# path: /hello
# Define function environment variables here
# environment:
# variable2: value2
# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"
sls package
output
Serverless: Running "serverless" installed locally (in service node_modules)
Error --------------------------------------------------
Error: Cannot find module 'ajv/dist/compile/codegen'
Require stack:
- /tmp/test/node_modules/ajv-keywords/dist/definitions/typeof.js
- /tmp/test/node_modules/ajv-keywords/dist/keywords/typeof.js
- /tmp/test/node_modules/ajv-keywords/dist/keywords/index.js
- /tmp/test/node_modules/ajv-keywords/dist/index.js
- /tmp/test/node_modules/serverless/lib/classes/ConfigSchemaHandler/index.js
- /tmp/test/node_modules/serverless/lib/Serverless.js
- /usr/local/lib/node_modules/serverless/lib/Serverless.js
- /usr/local/lib/node_modules/serverless/scripts/serverless.js
- /usr/local/lib/node_modules/serverless/bin/serverless.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/tmp/test/node_modules/ajv-keywords/src/definitions/typeof.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/tmp/test/node_modules/ajv-keywords/src/keywords/typeof.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/tmp/test/node_modules/ajv-keywords/src/keywords/index.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/tmp/test/node_modules/ajv-keywords/src/index.ts:3:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at ConfigSchemaHandler.validateConfig (/tmp/test/node_modules/serverless/lib/classes/ConfigSchemaHandler/index.js:102:5)
at Service.validate (/tmp/test/node_modules/serverless/lib/classes/Service.js:222:41)
at /tmp/test/node_modules/serverless/lib/Serverless.js:200:49
at tryCatcher (/tmp/test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/tmp/test/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/tmp/test/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/tmp/test/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/tmp/test/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/tmp/test/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/tmp/test/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/tmp/test/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/tmp/test/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 12.16.3
Framework Version: 2.11.1 (local)
Plugin Version: 4.1.2
SDK Version: 2.3.2
Components Version: 3.3.0
Installed version
Serverless: Running "serverless" installed locally (in service node_modules)
Framework Core: 2.18.0 (local)
Plugin: 4.4.2
SDK: 2.3.2
Components: 3.4.6
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:30 (14 by maintainers)
Top Results From Across the Web
Quasar Error: Cannot find module 'ajv/dist/compile/codegen'
To analyse the problem, you can always use the npm ls ajv command, to see, which module try to use something incompatible.
Read more >ajv-dist - npm
Start using ajv-dist in your project by running `npm i ajv-dist`. There are 4 other projects in the npm registry using ajv-dist.
Read more >Error: Cannot find module 'ajv/dist/compile/context' - Issuehunt
I'm getting the error "Error: Cannot find module 'ajv/dist/compile/context'" Using electron-store ^7.0.0 and up. Downgraded to 6.0.1 and everything worked ...
Read more >Quasar Error: Cannot find module 'ajv/dist/compile/codegen'
I just hit the same error several times recently. In my case the error was based on ajv-keywords and ajv-formats plugin incompatibility with...
Read more >Fix JHipster Issue v7.8.1 - Teten Nugraha - Medium
Error: Cannot find module 'ajv/dist/compile/codegen'. after I googling there are some solutions for it, one of them is you have to add one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was facing the same issue with, I temporarily solved it by installing
ajv@7.0.3
and now it’s added as dependency on mypackage.json
:It’s just a “workaround” for those who need to deploy their applications, and problably will be fixed asap. By the way I’m running the
serverless
v2.18.0,npm
v6.14.10 andnode
v10.19.0.I think there is something funny about version
2.18.0
ofserverless
. 3 separate users have posted here that they have run into the errorCannot find module 'ajv/dist/compile/codegen'
since upgrading to2.18.0
, and they didn’t have any errors with2.17.0
. Also, in the example I described in an earlier post, upgrading to2.18.0
caused the error in one project but not in the other. If this were a straight up bug innpm
v6, wouldn’t both of them fail?My projects don’t have a direct dependency on
ajv
either.