# Error: \_\_dirname is not defined after deploying assets canister

**URL:** <https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403>\
**Category:** Developers\
**Tags:** Functional-Programming\
**Created:** [January 10, 2024, 6:13am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403 "2024-01-10T06:13:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bytesun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bytesun/32/2682_2.png) [@bytesun](https://forum.dfinity.org/u/bytesun)\
**Post date:** [January 10, 2024, 6:13am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/1 "2024-01-10T06:13:47Z")

</div>

after deploy assets canister, got below error from browser console: [https://3hhuc-aqaaa-aaaah-aavra-cai.ic0.app/](https://3hhuc-aqaaa-aaaah-aavra-cai.ic0.app/)

> index.961d7240.js:2495 Uncaught ReferenceError: \_\_dirname is not defined  
> at index.961d7240.js:2495:29316  
> at index.961d7240.js:2495:29367

even rollback previous working code, still get the same error, please help

note: it works locally

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 10, 2024, 6:30am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/2 "2024-01-10T06:30:59Z")

</div>

Note a direct answer but, just in case helpful, `__dirname` was a NodeJS variable that has been deprecated in Node 18 (if I remember correctly). So did you bump your NodeJS version or any library and is maybe some polyfill at `npm run build` time not correctly applied anymore?

---

<div class="post-metadata">

**Author:** ![bytesun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bytesun/32/2682_2.png) [@bytesun](https://forum.dfinity.org/u/bytesun)\
**Post date:** [January 10, 2024, 6:37am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/3 "2024-01-10T06:37:59Z")

</div>

no, the same node v18.19.0, and no dependency changes

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 10, 2024, 6:44am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/4 "2024-01-10T06:44:04Z")

</div>

Maybe some code lead to loading the `gzip-size` library now and it was not the case before? But the issue is clear to me `__dirname` does not exist in the browser API. So I would be on a NodeJS polyfill not applied or something in that sort in build process. Hard to tell more, sorry.

 ![Capture d’écran 2024-01-10 à 07.41.24](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/6/6252737f8644f3c1a96d8f6a526b466910414aea.jpeg)

---

<div class="post-metadata">

**Author:** ![bytesun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bytesun/32/2682_2.png) [@bytesun](https://forum.dfinity.org/u/bytesun)\
**Post date:** [January 10, 2024, 2:08pm UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/5 "2024-01-10T14:08:12Z")

</div>

thanks, I am trying to drill down where it is. 😞

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 11, 2024, 6:21am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/6 "2024-01-11T06:21:45Z")

</div>

You found the solution?

---

<div class="post-metadata">

**Author:** ![bytesun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bytesun/32/2682_2.png) [@bytesun](https://forum.dfinity.org/u/bytesun)\
**Post date:** [January 11, 2024, 6:29am UTC](https://forum.dfinity.org/t/error-dirname-is-not-defined-after-deploying-assets-canister/26403/7 "2024-01-11T06:29:04Z")

</div>

no, I found where the issue it, the old module from commonjs, I tried [vite-plugin-node-polyfills - npm](https://www.npmjs.com/package/vite-plugin-node-polyfills), but no luck, so just disable it for now. Need to do more investigation.
