Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canvas[method] is not a function #770

Closed
welkinwong opened this issue May 17, 2016 · 8 comments
Closed

canvas[method] is not a function #770

welkinwong opened this issue May 17, 2016 · 8 comments

Comments

@welkinwong
Copy link

F:\nodercms\node_modules\canvas\lib\jpegstream.js:44
canvas[method](options.bufsize, options.quality, options.progressive, function(err, chunk){
^

TypeError: canvas[method] is not a function
at ...\node-canvas\lib\jpegstream.js:44:19
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

Windows 7 64

help me

@zbjornson
Copy link
Collaborator

zbjornson commented May 17, 2016

Do you have libjpeg-turbo setup on Windows? (See step 3 of https://github.com/Automattic/node-canvas/wiki/Installation%3A-Windows)

@welkinwong
Copy link
Author

@zbjornson yes,has been installed to default directory.

@zbjornson
Copy link
Collaborator

Good. Can you paste the log from when you run node-gyp rebuild please?

@ghost1face
Copy link

Any word on this one, I just ran into the same issue. libjpeg-turbo is setup in the default directory

@zbjornson
Copy link
Collaborator

To help any further, I'd need to see your logs from node-gyp rebuild when run in the canvas directory.

Also note that JPEG support on Windows requires canvas 2.x (currently in alpha). Try npm i canvas@v2.0.0-alpha.2. (Or npm install github:chearon/node-canvas-prebuilt#v2.0.0-alpha.2.)

@ghost1face
Copy link

ghost1face commented Aug 2, 2017

Thanks for your help. I went ahead and installed canvas@v2.0.0-alpha.2 and I still get the problem when using svg2img to convert to jpeg. Here's the output of node-gyp rebuild

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  Canvas.cc
  CanvasGradient.cc
  CanvasPattern.cc
  CanvasRenderingContext2d.cc
  color.cc
  Image.cc
  ImageData.cc
  init.cc
  win_delay_load_hook.cc
..\src\CanvasRenderingContext2d.cc(801): warning C4458: declaration of 'constructor' hides class member [C:\code\test
\node_modules\svg2img\node_modules\canvas\build\canvas.vcxproj]
  c:\code\test\node_modules\svg2img\node_modules\canvas\src\CanvasRenderingContext2d.h(72): note: see declaration of
  'Context2d::constructor' (compiling source file ..\src\CanvasRenderingContext2d.cc)
..\src\Canvas.cc(154): warning C4457: declaration of 'data' hides function parameter [C:\code\test\node_modules\svg2i
mg\node_modules\canvas\build\canvas.vcxproj]
  ..\src\Canvas.cc(150): note: see declaration of 'data'
     Creating library C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\canvas.lib and object C:\co
  de\test\node_modules\svg2img\node_modules\canvas\build\Release\canvas.exp
  Generating code
  Finished generating code
  canvas.vcxproj -> C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\canvas.node
  canvas.vcxproj -> C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\canvas.pdb (Full PDB)
  Copying C:/GTK/bin/libcairo-2.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\libcairo-
  2.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libfontconfig-1.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\libf
  ontconfig-1.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libexpat-1.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\libexpat-
  1.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libfreetype-6.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\libfre
  etype-6.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libpng14-14.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\libpng14
  -14.dll
          1 file(s) copied.
  Copying C:/GTK/bin/zlib1.dll to C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\zlib1.dll
          1 file(s) copied.
  win_delay_load_hook.cc
  Generating code
  Finished generating code
  canvas-postbuild.vcxproj -> C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\\canvas-postbuild.n
  ode
  canvas-postbuild.vcxproj -> C:\code\test\node_modules\svg2img\node_modules\canvas\build\Release\canvas-postbuild.pd
  b (Full PDB)

> canvas@2.0.0-alpha.2 install C:\code\test\node_modules\canvas
> node-gyp rebuild


C:\code\test\node_modules\canvas>if not defined npm_config_node_gyp (node "C:\Users\ghost1face\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  Copying C:/libjpeg-turbo64/bin/jpeg62.dll to C:\code\test\node_modules\canvas\build\Release\\jpeg62.dll
          1 file(s) copied.
  Backend.cc
  ImageBackend.cc
  PdfBackend.cc
  SvgBackend.cc
  Backends.cc
  Canvas.cc
  CanvasGradient.cc
  CanvasPattern.cc
  CanvasRenderingContext2d.cc
  closure.cc
  color.cc
  Image.cc
  ImageData.cc
  init.cc
  register_font.cc
  toBuffer.cc
  win_delay_load_hook.cc
     Creating library C:\code\test\node_modules\canvas\build\Release\canvas.lib and object C:\code\test\node_module
  s\canvas\build\Release\canvas.exp
  Generating code
  Finished generating code
  canvas.vcxproj -> C:\code\test\node_modules\canvas\build\Release\\canvas.node
  canvas.vcxproj -> C:\code\test\node_modules\canvas\build\Release\canvas.pdb (Full PDB)
  Copying C:/GTK/bin/libpangoft2-1.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libpangoft2-1.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libgthread-2.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libgthread-2.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libpangowin32-1.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libpangowin32-1.0-0.d
  ll
          1 file(s) copied.
  Copying C:/GTK/bin/libglib-2.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libglib-2.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libcairo-2.dll to C:\code\test\node_modules\canvas\build\Release\\libcairo-2.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libpango-1.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libpango-1.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libfontconfig-1.dll to C:\code\test\node_modules\canvas\build\Release\\libfontconfig-1.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libintl-8.dll to C:\code\test\node_modules\canvas\build\Release\\libintl-8.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libfreetype-6.dll to C:\code\test\node_modules\canvas\build\Release\\libfreetype-6.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libgmodule-2.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libgmodule-2.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libpangocairo-1.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libpangocairo-1.0-0.d
  ll
          1 file(s) copied.
  Copying C:/GTK/bin/libgobject-2.0-0.dll to C:\code\test\node_modules\canvas\build\Release\\libgobject-2.0-0.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libpng14-14.dll to C:\code\test\node_modules\canvas\build\Release\\libpng14-14.dll
          1 file(s) copied.
  Copying C:/GTK/bin/zlib1.dll to C:\code\test\node_modules\canvas\build\Release\\zlib1.dll
          1 file(s) copied.
  Copying C:/GTK/bin/libexpat-1.dll to C:\code\test\node_modules\canvas\build\Release\\libexpat-1.dll
          1 file(s) copied.
  win_delay_load_hook.cc
  Generating code
  Finished generating code
  canvas-postbuild.vcxproj -> C:\code\test\node_modules\canvas\build\Release\\canvas-postbuild.node
  canvas-postbuild.vcxproj -> C:\code\test\node_modules\canvas\build\Release\canvas-postbuild.pdb (Full PDB)
npm WARN worker-loader@0.8.1 requires a peer of webpack@>=0.9 <2 || ^2.1.0-beta || ^2.2.0 but none was installed.
npm WARN test@1.0.0 No repository field.

+ canvas@2.0.0-alpha.2
added 1 package and updated 1 package in 30.319s

@adokukin
Copy link

adokukin commented Jul 25, 2018

I guess, nobody need this after a year, but I met the same problem with 1.6.11. I follow this guide https://github.com/Automattic/node-canvas/wiki/Installation:-Windows and use default paths.

By glancing into sources I noticed that streamJPEGSync is added depending on HAVE_JPEG constant, which seems to be defined in binding.gyp on condition 'with_jpeg=="true"', which seems to be permanently turned off for windows in the very beginning of it
['OS=="win"', { 'variables': { 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle 'with_jpeg%': 'false', 'with_gif%': 'false', 'with_pango%': 'false', 'with_freetype%': 'false' }...

Also, in the same section where HAVE_JPEG is defined, the jpeg lib is referenced as
['OS=="win"', { 'libraries': [ '-l<(GTK_Root)/lib/jpeg.lib' ]
Which is also strange, as it will be linked from GTK default address and not the C:\libjpeg-turbo64.

Am I missing something here? Should I provide some arguments to npm or node-gyp to override something?

@zbjornson
Copy link
Collaborator

@adokukin only version 2.x supports JPEG on Windows.

We should probably setup stub methods for GIF, SVG and JPEG that provide nicer error messages when you attempt to call a GIV, SVG or JPEG method but don't have the libraries for those extensions.

zbjornson added a commit to zbjornson/node-canvas that referenced this issue Sep 3, 2018
zbjornson added a commit to zbjornson/node-canvas that referenced this issue Sep 3, 2018
`canvas.jpegStream` without JPEG support -> throw errors
`img.src = xxx` without support for that format -> emit error

Fixes Automattic#770
zbjornson added a commit to zbjornson/node-canvas that referenced this issue Sep 3, 2018
`canvas.jpegStream` without JPEG support -> throw errors
`img.src = xxx` without support for that format -> emit error

Fixes Automattic#770
chearon pushed a commit that referenced this issue Sep 4, 2018
`canvas.jpegStream` without JPEG support -> throw errors
`img.src = xxx` without support for that format -> emit error

Fixes #770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants