chartjs-node icon indicating copy to clipboard operation
chartjs-node copied to clipboard

Unhandled rejection Error: Cannot find module 'chart.js'

Open talaikis opened this issue 4 years ago • 2 comments

Unhandled rejection Error: Cannot find module 'chart.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at jsdom.envAsync.then.window (node_modules\chartjs-node\index.js:86:33)
    at tryCatcher (node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (node_modules\bluebird\js\release\promise.js:517:31)
    at Promise._settlePromise (node_modules\bluebird\js\release\promise.js:574:18)
    at Promise._settlePromise0 (node_modules\bluebird\js\release\promise.js:619:10)
    at Promise._settlePromises (node_modules\bluebird\js\release\promise.js:699:18)
    at Promise._fulfill (node_modules\bluebird\js\release\promise.js:643:18)
    at Object.done (node_modules\bluebird\js\release\nodeback.js:42:21)
    at process.nextTick (node_modules\jsdom\lib\jsdom.js:320:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)

Node 10.16, Windows 10

talaikis avatar Jul 18 '19 17:07 talaikis

@talaikis You probably already figured this out long ago, but just in case for anyone who may be reading...

This is because chart.js (required peer dependency) isn't installed. It's really easy to miss in the Getting Started instructions, but it's there. Got me too. 😅

npm install chart.js
yarn add chart.js

MastaAaron avatar Jan 09 '20 04:01 MastaAaron

@talaikis You probably already figured this out long ago, but just in case for anyone who may be reading...

This is because chart.js (required peer dependency) isn't installed. It's really easy to miss in the Getting Started instructions, but it's there. Got me too. 😅

npm install chart.js
yarn add chart.js

@MastaAaron This has been added as a dependency and still getting the error:

{
    "errorType": "Error",
    "errorMessage": "Cannot find module 'chart.js'",
    "code": "MODULE_NOT_FOUND",
    "stack": [
        "Error: Cannot find module 'chart.js'",
        "    at Function.t [as resolve] (/var/task/src/handler.js:1:1002)",
        "    at Object.r.freshRequire (/var/task/src/handler.js:1:3190)",
        "    at o (/var/task/src/handler.js:1:1235)",
        "    at new r.CanvasRenderService (/var/task/src/handler.js:1:1360)",
        "    at Runtime.o [as handler] (/var/task/src/handler.js:1:2973)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}

package.json looks like this:

{
  "name": "data-charts",
  "version": "1.0.0",
  "description": "Serverless webpack example using Typescript",
  "main": "src/handler.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "canvas": "^2.6.0",
    "chart.js": "^2.9.3",
    "chartjs-node-canvas": "^2.4.2",
    "serverless": "^1.58.0",
    "source-map-support": "^0.5.10"
  },
  "devDependencies": {
    "@types/aws-lambda": "^8.10.17",
    "@types/node": "^10.12.18",
    "jest": "^24.9.0",
    "serverless-offline": "^6.0.0-alpha.41",
    "serverless-webpack": "^5.2.0",
    "ts-loader": "^5.3.3",
    "typescript": "^3.2.4",
    "webpack": "^4.29.0"
  },
  "author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
  "license": "MIT"
}

Any other ideas?

mgaylord-branch avatar Feb 04 '20 02:02 mgaylord-branch