0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Denoで@discordjs/opusを使ってprism-mediaをimportする

Last updated at Posted at 2025-04-16

経緯

Denoを使い,DiscordのVCを横流しにするBotを作っていた.
Mori-chan氏の記事を参考にprism-mediaでVCのデータをOpusからRawデータにDecodeしようとしたところ,

error: Uncaught (in promise) Error: Cannot find module 'C:\Users\kazum\Desktop\discord_deno\node_modules\.deno\@discordjs+opus@0.10.0\node_modules\@discordjs\opus\prebuild\node-v108-napi-v3-win32-x64-unknown-unknown\opus.node

とimport関連のエラーが出た.
denoから

    hint: Add `"nodeModulesDir": "auto" option to `deno.json`, and then run 
          `deno install --allow-scripts=npm:<package> --entrypoint <script>` to setup `node_modules` directory.

とHintを提示されて試してもうまく解決できなかった.

解決法

Debugを進めていくと,@discordjs/opusのdynamic requireでエラーが出ていた.

index.js
const { resolve } = require('node:path');
const { find } = require('@discordjs/node-pre-gyp');

// eslint-disable-next-line import/no-dynamic-require
module.exports = require(find(resolve(__dirname, '..', 'package.json')));

prebuildはbuild時に生成される(GitHub)ので,requireの引数に与えられているPathをDebugして,そのディレクトリ上で

npm run build

を実行したところ,無事prebuildのファイルが生成された.

まとめ

Denoはlintとかfmtとかがコンパクトに収まっていてとても使いやすいけど,npm対応はまだ難しいのかな...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?