hashids.js icon indicating copy to clipboard operation
hashids.js copied to clipboard

self is not defined

Open jaequery opened this issue 4 years ago • 1 comments

Recently when deploying, we started getting this error:

ReferenceError: self is not defined

And it appears this issue occurs came about after it auto-upgraded to the latest 2.2.10, where previously we were using on 2.2.3 without issue.

We are currently using it via:

import Hashids from 'hashids/dist/hashids';

which isn't ideal but it works. We can'r enable esModuleInterop to true because that breaks other packages.

Any ideas what to do here?

jaequery avatar Dec 20 '21 23:12 jaequery

Hi @jaequery, can you give an example of how were you using it that it was broken?

niieani avatar Dec 24 '21 01:12 niieani

dist is for web browser usage. cjs and esm are for node.js or webpack.

If you use the dist files in node.js environment directly, you will get that error: ReferenceError: self is not defined

If you want to use dist for node.js, you should do a little modification:
replace self with ("object"==typeof self?self:{}) then it will can run both in browser and node.js

cuixiping avatar Apr 14 '23 06:04 cuixiping