我对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)
我不明白为什么。
这是 index.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);
PS:我是法语??如果我英语不好,很抱歉。
答案 0 :(得分:0)
Mac OS X v10.11 +:如果您最近更新到Mac OS X v10.11 +,并且在编译时遇到问题,请运行以下命令:xcode-select --install。阅读有关堆栈溢出问题的更多信息。如果您安装了xcode 10.0或更高版本,则要从源代码进行构建,您需要NPM 6.4.1或更高版本。