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

Getting "Cannot find module" error when using typescript #2260

Closed
Majoramari opened this issue Jun 22, 2023 · 2 comments
Closed

Getting "Cannot find module" error when using typescript #2260

Majoramari opened this issue Jun 22, 2023 · 2 comments

Comments

@Majoramari
Copy link

Majoramari commented Jun 22, 2023

Issue

I'm getting this error when suing typescript (javascript is fine) I tried to rebuild and remove the the node_modules and reinstall also tried bun.sh and deno, even tried with wsl (I'm on windows)

node:internal/modules/cjs/loader:1078
  throw err;
  ^

Error: Cannot find module '/mnt/c/Users/Major/Desktop/canvas/index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Note:
when using bun.sh I get this error instead

error: Cannot find module "../build/Release/canvas.node" from "/mnt/c/Users/Major/Desktop/canvas/node_modules/canvas/lib/bindings.js

Steps to Reproduce

import { createCanvas, loadImage } from 'canvas';

(async () => {
	const canvas = createCanvas(700, 250);

	const ctx = canvas.getContext('2d');

	const background = await loadImage('background.jpg');

	ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

	console.log('test');
})();

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas): -- canvas@2.11.2
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): wsl (debian) & windows 11 22h2
@Peter-MJ-Parker
Copy link

Did you by chance install this to your system globally rather than inside of a typescript project? It's being found inside my TS project but getting vulns that prevent a successful startup.

@RXNationGMG
Copy link

This occurs when the module is not properly installed or when the path to the module is incorrect, you can try

  1. Reinstall the canvas module.
  2. Verify the file path and existence of the 'background.jpg' file.
  3. Check the module resolution strategy and bundler configuration.
  4. Update the canvas module to the latest version.
  5. Ensure all dependencies are installed correctly.
  6. Consider using a different environment or machine.

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

3 participants