【发布时间】:2021-11-19 01:01:29
【问题描述】:
我目前正在使用 next@11.1.2 和 webpack v5 并在修复 mp3 加载时卡住了几个小时。我从堆栈和 GitHub 尝试了其他几种解决方案。它们都不适合我。
Type error: Cannot find module 'public/sounds/bighit.mp3' or its corresponding type declarations.
14 |
15 | // Assets
> 16 | import sound_bighit from "public/sounds/bighit.mp3"
| ^
info - Checking validity of types .%
这是我对 webpack 的最后一次配置:
const path = require('path')
const SRC = path.resolve(__dirname, 'public/sounds/')
module.exports = {
webpack: (config, { }) => {
config.module.rules.push({
test: /\.mp3$/,
incluse: SRC,
use: {
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'public/sounds/',
publicPath: 'public/sounds/'
}
}
})
// config.module.rules.push({
// test: /\.mp3$/,
// use: {
// loader: 'file-loader',
// },
// })
// config.module.rules.push({
// test: /\.mp3/,
// use: {
// loader: 'url-loader',
// },
// })
return config
}
}
【问题讨论】:
标签: reactjs typescript webpack next.js webpack-5