Nodejs Cannot find module '../build/Release/canvas'

30,228

Solution 1

In my case i have to spend lot of time to resolve this issue.

I just use "npm uninstall canvas" and then install using "npm i canvas"

Try this is if above option not works for you.

Solution 2

I had the same problem. The issue was that the install script for node-canvas never got executed, which is why the build folder was missing.

In my case, removing the yarn.lock file was the solution, as it skipped the node-canvas package installation for some reason. Once I let npm take care of the packages, it successfully installed node-canvas, ran the install script and the build folder showed up again.

Solution 3

Problem here looks like 1. Your node modules are installed in a different location But the node.js runtime is searching for it in a different place. Check the NODE_PATH and see if this is the case.

Refer the module loading explained in http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

Solution 4

It seemed like the install script of canvas haven't been called in my case, too. Instead of deleting the lock file I just called the script manually which solved the issue in my case (at least temporarily).

Therefore, if the canvas package has been installed already, go to /node_modules/canvas/ and run npm run install which creates the build directory.

Share:
30,228

Related videos on Youtube

friction
Author by

friction

Updated on July 09, 2022

Comments

  • friction
    friction almost 2 years

    I installed cairo, and node-canvas. I tried everything, but still can't find module.

    sudo apt-get install libcairo2-dev
    sudo npm install canvas
    sudo npm install canvas -g
    

    If I run require('canvas'), I get this error:

    Error: Cannot find module '../build/Release/canvas'
        at Function._resolveFilename (module.js:332:11)
        at Function._load (module.js:279:25)
        at Module.require (module.js:354:17)
        at require (module.js:370:17)
        at Object.<anonymous> (/home/tomas/node_modules/canvas/lib/bindings.js:2:18)
        at Module._compile (module.js:441:26)
        at Object..js (module.js:459:10)
        at Module.load (module.js:348:32)
        at Function._load (module.js:308:12)
        at Module.require (module.js:354:17)
    

    I use Ubuntu linux

    Thanks in advance.

    • soyuka
      soyuka over 11 years
      Check if the module is in your node_module directory and if it is, try to require the full path like require('./node_modules/canvas');
    • soyuka
      soyuka over 11 years
      You got the module in that directory ? Check github.com/LearnBoost/node-canvas/issues/137
    • friction
      friction over 11 years
      yes. test.js is in the same directory as the node_modules, and canvas directory is inside the node_modules
    • Muhammad Umer
      Muhammad Umer over 10 years
      canvas module is the worst of all, never had this many problems with anything in my life...been trying to do this for like 3 days...it's all over the place. putting direct path from c:... worked though..
    • programmerRaj
      programmerRaj almost 4 years
      For me I did npm clean-install and it worked.
  • edhgoose
    edhgoose over 5 years
    I had a similar problem, I had disabled install-scripts. Re-enabling them resolved my issue.
  • Patrick
    Patrick almost 3 years
    I was so skeptical this would work, but I thought I must try it. -- Solved my problem! thanks!