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

ReferenceError: __dirname is not defined in ES module scope #56

Open
davay42 opened this issue Jan 25, 2023 · 1 comment
Open

ReferenceError: __dirname is not defined in ES module scope #56

davay42 opened this issue Jan 25, 2023 · 1 comment

Comments

@davay42
Copy link

davay42 commented Jan 25, 2023

I try using the lib in my project to fix Windows builds via GitHub actions. Otherwise my projects build fine.

Seems like the lib isn't compatible with ES modules setup...

Here's the repo https://github.com/davay42/vitepress-pages

ReferenceError: __dirname is not defined in ES module scope
    at node_modules/.pnpm/app-root-path@3.1.0/node_modules/app-root-path/index.js (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vitepress-pages@0.9.0_vite-plugin-pages@0.28.0/node_modules/vitepress-pages/dist/index.js:129:26)
    at __require2 (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vitepress-pages@0.9.0_vite-plugin-pages@0.28.0/node_modules/vitepress-pages/dist/chunk-2LGAEF77.js:15:50)
    at file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vitepress-pages@0.9.0_vite-plugin-pages@0.28.0/node_modules/vitepress-pages/dist/index.js:138:36
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadConfigFromBundledFile (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vite@4.0.4/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:62084:21)
    at async loadConfigFromFile (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vite@4.0.4/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61969:28)
    at async resolveConfig (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vite@4.0.4/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61590:28)
    at async doBuild (file:///Users/davay/Documents/%D0%A4%D0%A0%D0%A3%D0%9A%D0%A2/Chromatone/chromatone.center/node_modules/.pnpm/vite@4.0.4/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44358:20)
    ```
@Creskendoll
Copy link

Creskendoll commented Jan 30, 2024

Here's my workaround using patch-package:

diff --git a/node_modules/app-root-path/index.js b/node_modules/app-root-path/index.js
index 7fd5bde..ad84c91 100644
--- a/node_modules/app-root-path/index.js
+++ b/node_modules/app-root-path/index.js
@@ -1,4 +1,4 @@
 'use strict';
 
 var lib = require('./lib/app-root-path.js');
-module.exports = lib(__dirname);
\ No newline at end of file
+module.exports = lib(typeof __dirname === 'undefined' ? process.cwd() : __dirname);

Simply put this inside the file patches/app-root-path+3.1.0.patch and run npx patch-package.

Be advised that I haven't fully tested this solution, so I don't know what the implications of using process.cwd() are.

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

2 participants