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]: Dynamic import in CJS output is broken #287

Closed
chenjiahan opened this issue Oct 14, 2024 · 3 comments
Closed

[Bug]: Dynamic import in CJS output is broken #287

chenjiahan opened this issue Oct 14, 2024 · 3 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@chenjiahan
Copy link
Member

Version

Rslib 0.0.11

Details

Dynamic import in CJS output is broken.

There are some conditions:

  • Use dynamic import in the source code
  • Output cjs format
  • package.json contains type: 'module'

For example, the input code is:

export async function main() {
  const { TsconfigPathsPlugin } = await import('tsconfig-paths-webpack-plugin');

  console.log(TsconfigPathsPlugin);
}

main();

Run the output code, and console.log(TsconfigPathsPlugin); get undefined.

Reproduce link

https://github.com/chenjiahan/rslib-repro-dynamic-import-cjs-interop

Reproduce Steps

  • tsup:

Image

  • Modern.js Module:

Image

  • Rslib:

Image

@chenjiahan chenjiahan added the 🐞 bug Something isn't working label Oct 14, 2024
@fi3ework
Copy link
Member

Duplicated with #121.

Current workaround

  output: {
    target: 'node',
+    externals: {
+      'tsconfig-paths-webpack-plugin': 'import tsconfig-paths-webpack-plugin',
+    },
  },

@fi3ework
Copy link
Member

It will be resolved when we implement external map for webpack and Rspack, we're already working on this.

@chenjiahan
Copy link
Member Author

Close duplicated issue

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

No branches or pull requests

2 participants