我在 NextJS 应用程序中使用 useSound,我想播放位于 /public/static 中的 mp3:
import notification from "../../public/static/notification.mp3"
它在运行时工作yarn dev
(正在播放声音,没有错误),但是在使用yarn prod
以下命令构建时会引发错误:
Type error: Cannot find module '../../public/static/notification.mp3' or its corresponding type declarations.
有人可以帮我吗?我一直在浏览互联网/SO/github,并尝试了几件事,包括修改next.config.js
:
webpack(config, { isServer }) {
config.module.rules.push({
test: /\.(ogg|mp3|wav|mpe?g)$/i,
exclude: config.exclude,
use: [
{
loader: require.resolve('url-loader'),
options: {
limit: config.inlineImageLimit,
fallback: require.resolve('file-loader'),
publicPath: `${config.assetPrefix}/_next/static/`,
outputPath: `${isServer ? '../' : ''}static/`,
name: '[name]-[hash].[ext]',
esModule: config.esModule || false,
},
},
],
});
return config;
},
没有成功..
好吧显然它是那么容易,因为是:更新next-env.d.ts
与
declare module '*.mp3' {
const src: string;
export default src;
}
如果有人能解释它是如何工作的,那就太好了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句