簡體   English   中英

«Canvas» 與 NodeJS 的使用:«無法找到模塊 '../build/Release/canvas.node'»

[英]Utilisation of «Canvas» with NodeJS : «Cannot find module '../build/Release/canvas.node'»

我在使用 «Canvas» 庫和 NodeJS 時遇到了問題。 當我在終端中啟動此命令時:

 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);
我在 Qwant 有搜索幫助,但我沒有發現任何問題。 如果你能幫助我,非常感謝。

PS:我是法國人🇫🇷,如果我英語不好,請見諒。

文檔

Mac OS X v10.11+:如果您最近更新到 Mac OS X v10.11+ 並且在編譯時遇到問題,請運行以下命令:xcode-select --install。 在 Stack Overflow 上閱讀有關此問題的更多信息。 如果您安裝了 xcode 10.0 或更高版本,為了從源代碼構建,您需要 NPM 6.4.1 或更高版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM