-
-
Notifications
You must be signed in to change notification settings - Fork 256
Open
Description
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.6Used 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!)
Metadata
Metadata
Assignees
Labels
No labels