我想在我的 nextjs vercel 应用程序中使用 google 云语音,但在导入模块时遇到问题`
const speech = require('google-cloud/speech');
我尝试配置 webpack5 文件,但没有为演讲记录任何内容
//next.config.js
module.exports = withBundleAnalyzer({ \
webpack5: true,
webpack: (config) => {
config.resolve.fallback = { 'google-cloud/speech': false };
return config;
},
})
如有任何帮助,我们将不胜感激
api/路由文件
import { getAuth } from "firebase/auth";
import dynamic from "next/dynamic";
const speech = require('google-cloud/speech');
export async function POST(req: NextRequest) {
console.log(speech, 'lx')
const body = await req.json();
如果 this 是您尝试使用的包,那么您应该在导入中使用
@google-cloud/speech
引用它。请注意@
。您应该通过运行 npm i @google-cloud/speech
来仔细检查您是否已正确安装它。
此外,看起来您在路由文件中使用了 ES 语法(请参阅 es 与 commonjs 导入),因此您实际上应该像这样导入模块:
import speech from '@google-cloud/speech'
然后,我建议阅读其文档以了解如何正确使用它这里。祝你好运!