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

fix(bundling): rspack should allow ES config module imports #29095

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

meeroslav
Copy link
Contributor

Reproduction repo: https://github.com/olaf-cichocki/sample

Current Behavior

When using mjs config file we end up with following error:

⚠️ Unable to construct project graph.
Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
      An error occurred while processing files for the @nx/rspack/plugin plugin.
    - apps/appA/rspack.config.mjs: require() of ES Module /Users/miro/Dev/Testbox/sample/apps/appA/rspack.config.mjs not supported.
  Instead change the require of /Users/miro/Dev/Testbox/sample/apps/appA/rspack.config.mjs to a dynamic import() which is available in all CommonJS modules.
      Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/miro/Dev/Testbox/sample/apps/appA/rspack.config.mjs not supported.
      Instead change the require of /Users/miro/Dev/Testbox/sample/apps/appA/rspack.config.mjs to a dynamic import() which is available in all CommonJS modules.
          at resolveUserDefinedRspackConfig (/Users/miro/Dev/Testbox/sample/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_react-dom@1_7iwdcl66l7me4m7pewq22wegge/node_modules/@nx/rspack/src/utils/resolve-user-defined-rspack-config.js:19:16)
          at createRspackTargets (/Users/miro/Dev/Testbox/sample/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_react-dom@1_7iwdcl66l7me4m7pewq22wegge/node_modules/@nx/rspack/src/plugins/plugin.js:65:98)
          at createNodesInternal (/Users/miro/Dev/Testbox/sample/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_react-dom@1_7iwdcl66l7me4m7pewq22wegge/node_modules/@nx/rspack/src/plugins/plugin.js:51:34)
          at async /Users/miro/Dev/Testbox/sample/node_modules/.pnpm/[email protected]/node_modules/nx/src/project-graph/plugins/utils.js:10:27
          at async Promise.all (index 0)

Expected Behavior

Using EU module config files is supported

Related Issue(s)

Fixes #

Thank you @olaf-cichocki for reporting the issue.

@meeroslav meeroslav self-assigned this Nov 27, 2024
@meeroslav meeroslav requested a review from a team as a code owner November 27, 2024 13:43
Copy link

vercel bot commented Nov 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2024 2:53pm

@@ -18,7 +18,7 @@ export function resolveUserDefinedRspackConfig(
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
if (!/\.(ts|mts|cts)$/.test(path)) {
return require(path);
return import(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the function to return a Promise in some circumstances.

That's going to impact how this function is used in config.ts and plugin.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants