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

remove useless module import #103

Open
1 of 2 tasks
uinz opened this issue Nov 29, 2024 · 0 comments
Open
1 of 2 tasks

remove useless module import #103

uinz opened this issue Nov 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@uinz
Copy link
Contributor

uinz commented Nov 29, 2024

Problem

image

When --env.NODE_ENV=production is set, require will be treeshaken away, so import { createRequire } from 'module' will no longer be useful.

image

Expected behavior

There are two improvement suggestions here:

  1. When the module is not used, perform treeshaking to remove it.
  2. Allow the behavior of create-require to be disabled.

The first point can be achieved by configuring the behavior of create-require resolveId to mark the module module as side-effect-free.

rollup options

resolveId: source => (
  (source === virtualModuleName)
  ? { id: source, moduleSideEffects: false }
  //              ^^^^^^^^^^^^^^^^^^^^^^^^
  : null
),

Minimal reproduction URL

https://stackblitz.com/edit/stackblitz-starters-xvwvt9?file=dist%2Findex.cjs

Version

v2.5.1

Node.js version

v22.6.0

Package manager

pnpm

Operating system

macOS

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work financially will speed up resolution

  • I'm willing to offer financial support
@uinz uinz added the bug Something isn't working label Nov 29, 2024
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

1 participant