Issue
I'm using useSound within a NextJS app, and I would like to play a mp3 located in /public/static:
import notification from "../../public/static/notification.mp3"
It is working when running yarn dev
(sound is playing, no errors), but it raises an error when building with yarn prod
:
Type error: Cannot find module '../../public/static/notification.mp3' or its corresponding type declarations.
Could someone help me with that? I've been looking over the internet/SO/github, and tried several things, including modifying 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;
},
Without success..
Solution
Ok apparently it is as easy as that: update next-env.d.ts
with
declare module '*.mp3' {
const src: string;
export default src;
}
If anyone can explain how that works, it would be nice.
Answered By - Binajmen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.