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

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

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

ambarvm opened this issue Mar 5, 2025 · 0 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.

@ambarvm ambarvm linked a pull request Apr 5, 2025 that will close this issue
9 tasks
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

Successfully merging a pull request may close this issue.

1 participant