Error: Can't resolve 'canvas'

See original GitHub issue

Basic info:

  • Node.js version: 11.5.0
  • jsdom version: 16.4.0
  • @angular/core 10.0.5

Minimal reproduction case

const { JSDOM } = require("jsdom");
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);

$ = require('jquery')(dom.window);

Issue faced:

I am trying to use jsdom to create window and document objects for my SSR angular project. however, I am experiencing this error. I am using the window to attempt to initialize the jQuery library as previously I kept getting a jQuery requires window error.

ERROR in ./node_modules/jsdom/lib/jsdom/utils.js
Module not found: Error: Can't resolve 'canvas' in '/Users/amanda/Documents/project/node_modules/jsdom/lib/jsdom'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

28reactions
crazyaircommented, Nov 26, 2020

install canval


 ERROR  Failed to compile with 1 errors                                                                                                                                              10:08:39 AM

 error  in ./node_modules/canvas/build/Release/canvas.node

Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

demo:https://github.com/crazyair/umi-dompurify-demo

9reactions
crazyaircommented, Nov 27, 2020

try to install https://www.npmjs.com/package/canvas to your project.

no fix it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot install canvas on npm - node.js - Stack Overflow
I used the command npm install --build-from-source canvas, please can I have help?
Read more >
canvas - npm
11+ and are experiencing trouble when compiling, run the following command: xcode-select --install . Read more about the problem on Stack ...
Read more >
webpack/webpack - Gitter
ERROR in ./app/js/lib/fabric.min.js Module not found: Error: Cannot resolve module 'canvas' in E:\Dropbox\projects\avp\app\js\lib @ .
Read more >
Getting started with react and canvas via Konva
react-konva is a JavaScript library for drawing complex canvas graphics using ... ModuleNotFoundError: Module not found: Error: Can't resolve 'canvas' in ...
Read more >
Canvas.node webpack isn't working with node-loader
I've discovered that npm install canvas actually in… ... 12:59:35 PM: Module not found: Can't resolve 'bufferutil' in '/opt/build/repo/node_modules/ws/lib'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found