使用NodeJS使用«画布»:"找不到模块"。/build/Release/canvas.node'»



我在NodeJS中使用«Canvas»库时遇到了问题。当我在终端中启动此命令时:

node .

终端回复我这个:

module.js:549
throw err;
^
Error: Cannot find module '../build/Release/canvas.node'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/user/nodejs-canvas/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

我不明白为什么。

这是索引.js文件:

const Discord = require('discord.js');
const Canvas = require('canvas');
const client = new Discord.Client();
client.once('ready', () => {
	console.log('Ready!');
});
client.on('guildMemberAdd', async member => {
	const channel = member.guild.channels.find(ch => ch.name === 'member-log');
	if (!channel) return;
	const canvas = Canvas.createCanvas(700, 250);
	const ctx = canvas.getContext('2d');
	const background = await Canvas.loadImage('./wallpaper.jpg');
	ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
	ctx.strokeStyle = '#74037b';
	ctx.strokeRect(0, 0, canvas.width, canvas.height);
	ctx.font = '28px sans-serif';
	ctx.fillStyle = '#ffffff';
	ctx.fillText('Bienvenue,', canvas.width / 2.5, canvas.height / 3.5);
	// Add an exclamation point here and below
	ctx.font = applyText(canvas, `${member.displayName}!`);
	ctx.fillStyle = '#ffffff';
	ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
	ctx.beginPath();
	ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
	ctx.closePath();
	ctx.clip();
	const avatar = await Canvas.loadImage(member.user.displayAvatarURL);
	ctx.drawImage(avatar, 25, 25, 200, 200);
	const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
	channel.send(`Bienvenue sur le serveur, ${member}!`, attachment);
});
client.on('message', async message => {
	if (message.content === '!join') {
		client.emit('guildMemberAdd', message.member || await message.guild.fetchMember(message.author));
	}
});
client.login(SECRET TOKEN);
我在Qwant中有搜索帮助,但我没有发现任何间歇。 如果你能帮助我,非常感谢。

PS :我是法国🇫🇷人,如果我的英语不好,很抱歉。

从文档中:

Mac OS X v10.11+:

如果您最近更新到 Mac OS X v10.11+ 并在编译时遇到问题,请运行以下命令:xcode-select --install。阅读有关堆栈溢出问题的更多信息。如果您安装了 xcode 10.0 或更高版本,为了从源代码构建,您需要 NPM 6.4.1 或更高版本。

最新更新