mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
4669a15362
fixed: #82106 The error was cause by the follow reason, when pass: ```ts const nextConfig: NextConfig = { /* config options here */ turbopack: { rules: { '*.txt': { loaders: ['./test-file-loader.js'], as: '*.js', }, } } }; ``` and the project directory as follows: ```bash src |_ app |_ index.tsx |_ text.txt ``` The loader will deal the `text.txt` under `src/app`, then the loader will resolve path like: ```ts require.resolve('./test-file-loader.js', paths: ['/Users/next-app/src/app']) ``` Because the resource dir the `dirname(resoucePath)`, and the resourcePath is `/Users/next-app/src/app/text.txt`, this will never resolve the right loader path here. So I just add a more `path` param(which is `contextDir`) for the require.resolve function, it will help the loader to find the right path here.
31 lines
584 B
JavaScript
31 lines
584 B
JavaScript
/**
|
|
* @type {import('next').NextConfig}
|
|
*/
|
|
const nextConfig = {
|
|
turbopack: {
|
|
rules: {
|
|
'*.txt': {
|
|
loaders: ['./test-file-loader.js'],
|
|
as: '*.js',
|
|
},
|
|
'*.mp4': {
|
|
loaders: [require.resolve('./test-file-loader.js')],
|
|
as: '*.js',
|
|
},
|
|
},
|
|
},
|
|
webpack(config) {
|
|
config.module.rules.push({
|
|
test: /\.txt/,
|
|
use: './test-file-loader.js',
|
|
})
|
|
config.module.rules.push({
|
|
test: /\.mp4/,
|
|
use: require.resolve('./test-file-loader.js'),
|
|
})
|
|
return config
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig
|