Files
zoomdong 4669a15362 fix(turbopack): webpack-loaders failed to resolve relative path (#82720)
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.
2025-08-18 12:54:38 -07:00

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