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

Bundling of tinyexec removes alias which prevents duplicate import of createRequire #235

Open
5 of 7 tasks
Codex- opened this issue Sep 23, 2024 · 0 comments
Open
5 of 7 tasks

Comments

@Codex-
Copy link

Codex- commented Sep 23, 2024

Describe the bug

Discovered on my action which uses ni as a package opposed to a CLI tool (which it rocks at 🚀)

tinyexec contains an import of createRequire:

import { createRequire as __tinyexec_cr } from "node:module";
const require = __tinyexec_cr(import.meta.url);

When ni generates bundles, the code gets transformed to:

// ni.7b6d0b44.mjs
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

When bundling ni in a project that also declares a createRequire banner:

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
//...
import { createRequire } from "node:module";
var require2 = createRequire(import.meta.url);

Resulting in the error:

Identifier 'createRequire' has already been declared

Unsure what the best approach here would be to prevent unbuild/rollup from collapsing this import alias down 🤔

The tinyexec dist contains the alias import still

Mainly opened this for searchability / awareness

Resolved on my end by aliasing my own createRequire

Reproduction

https://github.com/Codex-/ni-createRequire-bundle-issue

System Info

System:
    OS: macOS 14.6.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 102.28 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.asdf/installs/nodejs/20.17.0/bin/node
    npm: 10.8.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.15.9 - ~/.asdf/installs/nodejs/20.17.0/bin/pnpm
    bun: 1.1.21 - ~/.bun/bin/bun
  Browsers:
    Chrome: 129.0.6668.59
    Safari: 17.6

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)
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

No branches or pull requests

1 participant