Skip to content

[@rollup/plugin-commonjs] no way to use path outside current dir in dynamicRequireTargets #1855

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

Closed
ambarvm opened this issue Mar 5, 2025 · 2 comments · May be fixed by #1859
Closed

[@rollup/plugin-commonjs] no way to use path outside current dir in dynamicRequireTargets #1855

ambarvm opened this issue Mar 5, 2025 · 2 comments · May be fixed by #1859

Comments

@ambarvm
Copy link

ambarvm commented Mar 5, 2025

Expected Behavior

Build

npm run build -w server

Run

npm start -w server

xhr-sync-worker.js in jsdom should be correctly included in dynamicRequireTargets as configured.
Expected output

Hello jsdom [object Window]!

Actual Behavior

Executing the output script fails with this error

Error: Cannot find module './xhr-sync-worker.js'
Require stack:
- /home/projects/rollup-repro-lhjkysjm/server/dist/main.js
    at _0x4a2c83 (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:21530)
    at internal/modules/cjs/loader/Module._resolveFilename (node:internal/modules/cjs/loader:144:12334)
    at resolve (node:internal/modules/helpers:163:2873)
    at requireXMLHttpRequestImpl (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:197494:51)
    at requireXMLHttpRequest/< (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:199147:16)
    at requireXMLHttpRequest (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:199148:4)
    at requireInterfaces (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:208335:20)
    at requireWindow (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:209876:32)
    at requireApi (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:210999:27)
    at requireMain (/home/projects/rollup-repro-lhjkysjm/server/dist/main.js:211328:20)
    at _0x339e27 (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:811403)
    at internal/modules/cjs/loader/Module.prototype._compile (node:internal/modules/cjs/loader:144:14246)
    at internal/modules/cjs/loader/Module."] (node:internal/modules/cjs/loader:144:14855)
    at internal/modules/cjs/loader/Module.prototype.load (node:internal/modules/cjs/loader:144:12820)
    at internal/modules/cjs/loader/Module._load (node:internal/modules/cjs/loader:144:10273)
    at executeUserEntryPoint (node:internal/modules/run_main:165:1641)
    at internal/main/run_main_module (node:internal/main/run_main_module:138:398)
    at _0x5dd822 (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:1444999)
    at executeBootstrapper (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:908549)
    at startExecution (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:1476481)
    at run (https://rollupreprolhjkysjm-orah.w-corp-staticblitz.com/blitz.495c5120.js:40:1475098) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/projects/rollup-repro-lhjkysjm/server/dist/main.js' ]
}

Additional Information

After going through change log and a bit of console log debugging, I realized this is caused by recent dependency change from glob -> fdir in v28. The reproduction works as expected if commonjs plugin version is changed to v27.
While absolute paths are not working anymore, based on the way fdir works, I believe currently there is no way to configure dynamicRequireTargets to include a file outside cwd (in this case server directory).

A possible solution is to add a config option to pass a root dir to crawl() here. In my case, crawl('..') works.

Copy link

stale bot commented May 8, 2025

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

@stale stale bot closed this as completed May 8, 2025
@ambarvm
Copy link
Author

ambarvm commented May 8, 2025

I did submit a PR #1859
Please consider reopening

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

Successfully merging a pull request may close this issue.

1 participant