Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: modifying resolve.extensions in Rspack config object doesn't work #3410

Closed
mdrobny opened this issue Sep 8, 2024 · 2 comments · Fixed by #3437
Closed

[Bug]: modifying resolve.extensions in Rspack config object doesn't work #3410

mdrobny opened this issue Sep 8, 2024 · 2 comments · Fixed by #3437
Labels
🐞 bug Something isn't working

Comments

@mdrobny
Copy link

mdrobny commented Sep 8, 2024

Version

System:
  OS: macOS 14.6.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 269.59 MB / 32.00 GB
  Shell: 5.9 - /bin/zsh
Browsers:
  Chrome: 128.0.6613.120
  Safari: 17.6
npmPackages:
  @rsbuild/core: workspace:* => 1.0.1-rc.5 
  @rsbuild/plugin-react: workspace:* => 1.0.1-rc.5

Details

when using Rsbuild, I noticed that modifying resolve.extensionsproperty in Rspack config object doesn't work.
Luckily it works when modifying the Rspack config with a function so I it's possible to workaround the problem currently.
But I expected to achieve it by just modifying the object like the docs

Reproduce link

https://codepen.io/mdrobny/pen/KKjJVwN

Reproduce Steps

  1. try to modify resolve.extensions in example rsbuild.config.ts like this
export default defineConfig({
  plugins: [pluginReact()],
  tools: {
    rspack: {
      resolve: {
        extensions: ['.jsx', '.tsx', '.ts', '.js'],
      },
    }
  }
});
  1. add App.jsx component in src folder
const App = () =>  <div>App JSX</div>

export default App;
  1. run rsbuild dev

  2. open website and you can still see content from App.tsx. Rsbuild should use App.jsx file because jsx extension has priority over tsx but it doesn't

    • image
  3. Change rsbuild.config.ts to

export default defineConfig({
  plugins: [pluginReact()],
  tools: {
    rspack: config => {
      config.resolve ||= {};
      config.resolve.extensions = ['.jsx', '.tsx', '.ts', '.js'];
    }
  }
});
  1. run rsbuild dev
  2. open website and now content is App JSX so it worked
    • image
@mdrobny mdrobny added the 🐞 bug Something isn't working label Sep 8, 2024
@chenjiahan
Copy link
Member

Rsbuild uses webpack-merge to merge Rspack config objects, so the extensions array is merged instead of overwritten.

image

https://rsbuild.dev/config/tools/rspack

@mdrobny
Copy link
Author

mdrobny commented Sep 10, 2024

@chenjiahan thanks for mentioning this in the docs 💪 it will save people some trouble.

Great job with rsbuild BTW 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants