js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

ReferenceError: TextDecoder is not defined

Open ekumahost opened this issue 4 years ago • 17 comments

My script been throwing this error no headways.. any idea

  • Version: 47.0.1 and also the latest version
  • Platform: Linux (google cloud)
  • Subsystem:

Severity: high

Description:

2021-04-09 12:22:05 at Function.Module._load (internal/modules/cjs/loader.js:585:3) 2021-04-09 12:22:05 at tryModuleLoad (internal/modules/cjs/loader.js:593:12) 2021-04-09 12:22:05 at Module.load (internal/modules/cjs/loader.js:653:32) 2021-04-09 12:22:05 at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) 2021-04-09 12:22:05 at Module._compile (internal/modules/cjs/loader.js:776:30) 2021-04-09 12:22:05 at Object. (/www/node_modules/multibase/src/constants.js:4:14) 2021-04-09 12:22:05 at require (internal/modules/cjs/helpers.js:25:18) 2021-04-09 12:22:05 at Module.require (internal/modules/cjs/loader.js:690:17) 2021-04-09 12:22:05 at Function.Module._load (internal/modules/cjs/loader.js:585:3) 2021-04-09 12:22:05 at tryModuleLoad (internal/modules/cjs/loader.js:593:12) 2021-04-09 12:22:05 at Module.load (internal/modules/cjs/loader.js:653:32) 2021-04-09 12:22:05 at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) 2021-04-09 12:22:05 at Module._compile (internal/modules/cjs/loader.js:776:30) 2021-04-09 12:22:05 at Object. (/www/node_modules/multibase/src/base.js:3:24) 2021-04-09 12:22:05 at require (internal/modules/cjs/helpers.js:25:18) 2021-04-09 12:22:05 at Module.require (internal/modules/cjs/loader.js:690:17) 2021-04-09 12:22:05 at Function.Module._load (internal/modules/cjs/loader.js:585:3) 2021-04-09 12:22:05 at tryModuleLoad (internal/modules/cjs/loader.js:593:12) 2021-04-09 12:22:05 at Module.load (internal/modules/cjs/loader.js:653:32) 2021-04-09 12:22:05 at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) 2021-04-09 12:22:05 at Module._compile (internal/modules/cjs/loader.js:776:30) 2021-04-09 12:22:05 at Object. (/www/node_modules/multibase/src/util.js:3:21) 2021-04-09 12:22:05 ReferenceError: TextDecoder is not defined 2021-04-09 12:22:05 2021-04-09 12:22:05 ^ 2021-04-09 12:22:05 const textDecoder = new TextDecoder() 2021-04-09 12:22:05 /www/node_modules/multibase/src/util.js:3

Steps to reproduce the error:

ekumahost avatar Apr 09 '21 11:04 ekumahost

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

welcome[bot] avatar Apr 09 '21 11:04 welcome[bot]

I'm having the same issue when running the Create React App example project

danielcjacks avatar Apr 09 '21 18:04 danielcjacks

Same here. Created a massively simplified CRA repo to reproduce: https://github.com/elmariachi111/ipfs-textencoder-demo

elmariachi111 avatar Apr 09 '21 20:04 elmariachi111

What version of node are you running?

achingbrain avatar Apr 09 '21 20:04 achingbrain

Built that with node 12.22, 14.15, 15.14 tried with yarn, npm, pnpm.

elmariachi111 avatar Apr 09 '21 20:04 elmariachi111

What version of node are you running?

node:10.16.0-alpine [Docker]

ekumahost avatar Apr 09 '21 20:04 ekumahost

guess that's related to the latest multibase releases (https://github.com/multiformats/js-multibase/compare/v4.0.2...v4.0.4) they dropped the dependency on the generic web-encoding dependency lately: https://github.com/Gozala/web-encoding/compare/v1.1.3...v1.1.4 . Curiously, the error seems to be thrown in a multibase module @3.1.2, but the verison that ipfs-core 0.5.4 requires is definitely ^4.0.2... https://github.com/ipfs/js-ipfs/blob/74bfce3c12f743b8c1cda4b2160b25802f9f27d6/packages/ipfs-core/package.json#L114

image

elmariachi111 avatar Apr 09 '21 20:04 elmariachi111

@ekumahost please upgrade to a supported node version - 14 or 15.

@elmariachi111 you are running in a browser and likely have a different problem

achingbrain avatar Apr 09 '21 20:04 achingbrain

it's very lkely an issue with CRA. Runs fine inside nextjs & parcel, created 2 PRs for that: https://github.com/elmariachi111/ipfs-textencoder-demo/pulls . It's quite likely that somewhen on the way CRA support broke. I just checked whether your official CRA sample (without Typescript) runs, but I found that by plainly building and running it, it shows the same error as above... (so https://github.com/ipfs/js-ipfs/tree/master/examples/browser-create-react-app is also not working here, node 14.15.3

elmariachi111 avatar Apr 09 '21 23:04 elmariachi111

I have a project that is also being affected by this.

Dependency tree

└─┬ [email protected]
  ├─┬ [email protected]
  │ └── [email protected] deduped
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   └─┬ [email protected]
  │     ├── [email protected]
  │     └─┬ [email protected]
  │       └── [email protected] deduped
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └─┬ [email protected]
  │ │   └── [email protected]
  │ └─┬ [email protected]
  │   └── [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   └─┬ [email protected]
  │     └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ └─┬ [email protected]
  │   └── [email protected] deduped
  ├── [email protected]
  ├─┬ [email protected]
  │ └── [email protected] deduped
  └─┬ [email protected]
    └── [email protected] deduped

Avoid using (^) in the dependencies, it is really dangerous.

RomarQ avatar Apr 10 '21 00:04 RomarQ

A workaround, while it doesn't get fixed:

npm i --save-exact [email protected]

Commit that introduced the problem: https://github.com/Gozala/web-encoding/commit/3992702cefa89e3e2f67a0b29bed41d290c5e6a8

RomarQ avatar Apr 10 '21 01:04 RomarQ

@ekumahost please upgrade to a supported node version - 14 or 15.

@elmariachi111 you are running in a browser and likely have a different problem

I think this is going to fix the issue. trying to test and verify.

ekumahost avatar Apr 10 '21 06:04 ekumahost

A workaround, while it doesn't get fixed:

npm i --save [email protected]

Commit that introduced the problem: Gozala/web-encoding@3992702

@RomarQ think it's not helping if I install web-encoding locally ;) But you know what? When I add

  "resolutions": {
    "web-encoding": "1.1.3"
  },

to my package.json file, it just runs fine :) (might only work with yarn)

elmariachi111 avatar Apr 10 '21 09:04 elmariachi111

I have upgraded node to version >14.x and issue fixed.

ekumahost avatar Apr 11 '21 11:04 ekumahost

I am facing the same while retrieving the data from mongodb.

yus1uf avatar Sep 12 '21 08:09 yus1uf

@achingbrain This is not working for me in ipfs-webui with node version 16.12.0 when I'm trying to upgrade dependencies: https://github.com/ipfs/ipfs-webui/issues/1965

> run-s -cl test:unit test:build test:e2e

[test:unit ]
[test:unit ] > [email protected] test:unit /Users/sgtpooki/code/work/protocol.ai/ipfs/webui
[test:unit ] > react-scripts test --env=jsdom --runInBand --watchAll=false
[test:unit ]
[test:unit ] watchman warning:  Recrawled this watch 1513 times, most recently because:
[test:unit ] MustScanSubDirs UserDroppedTo resolve, please review the information on
[test:unit ] https://facebook.github.io/watchman/docs/troubleshooting.html#recrawl
[test:unit ] To clear this warning, run:
[test:unit ] `watchman watch-del '/Users/sgtpooki/code/work/protocol.ai/ipfs/webui' ; watchman watch-project '/Users/sgtpooki/code/work/protocol.ai/ipfs/webui'`
[test:unit ]
[test:unit ] PASS src/bundles/node-bandwidth-chart.test.js
[test:unit ] PASS src/bundles/peer-locations.test.js
[test:unit ] PASS src/loader/AsyncRequestLoader.test.js
[test:unit ] PASS src/lib/files.test.js
[test:unit ] PASS src/lib/dnd-backend.test.js
[test:unit ] PASS src/lib/count-dirs.test.js
[test:unit ] FAIL src/bundles/files.test.js
[test:unit ]   ● Test suite failed to run
[test:unit ]
[test:unit ]     ReferenceError: TextDecoder is not defined
[test:unit ]
[test:unit ]        8 | import map from 'it-map'
[test:unit ]        9 | import last from 'it-last'
[test:unit ]     > 10 | import CID from 'cids'
[test:unit ]          | ^
[test:unit ]       11 |
[test:unit ]       12 | import { spawn, perform, send, ensureMFS, Channel, sortFiles, infoFromPath } from './utils'
[test:unit ]       13 | import { IGNORED_FILES, ACTIONS } from './consts'
[test:unit ]
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/util.js:3:21)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/base.js:3:24)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/constants.js:4:14)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/index.js:7:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multihashes/src/index.js:6:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/cids/src/index.js:3:12)
[test:unit ]       at Object.<anonymous> (src/bundles/files/actions.js:10:1)
[test:unit ]       at Object.<anonymous> (src/bundles/files/index.js:4:1)
[test:unit ]       at Object.<anonymous> (src/bundles/files.test.js:3:1)
[test:unit ]
[test:unit ] FAIL src/bundles/peer-bandwidth.test.js
[test:unit ]   ● Test suite failed to run
[test:unit ]
[test:unit ]     ReferenceError: TextDecoder is not defined
[test:unit ]
[test:unit ]       1 | import multihashing from 'multihashing-async'
[test:unit ]     > 2 | import CID from 'cids'
[test:unit ]         | ^
[test:unit ]       3 | import { promisify } from 'util'
[test:unit ]       4 | import Crypto from 'crypto'
[test:unit ]       5 |
[test:unit ]
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/util.js:3:21)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/base.js:3:24)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/constants.js:4:14)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/index.js:7:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multihashes/src/index.js:6:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/cids/src/index.js:3:12)
[test:unit ]       at Object.<anonymous> (test/helpers/cid.js:2:1)
[test:unit ]       at Object.<anonymous> (src/bundles/peer-bandwidth.test.js:4:1)
[test:unit ]
[test:unit ] FAIL src/bundles/notify.test.js
[test:unit ]   ● Test suite failed to run
[test:unit ]
[test:unit ]     ReferenceError: TextDecoder is not defined
[test:unit ]
[test:unit ]        8 | import map from 'it-map'
[test:unit ]        9 | import last from 'it-last'
[test:unit ]     > 10 | import CID from 'cids'
[test:unit ]          | ^
[test:unit ]       11 |
[test:unit ]       12 | import { spawn, perform, send, ensureMFS, Channel, sortFiles, infoFromPath } from './utils'
[test:unit ]       13 | import { IGNORED_FILES, ACTIONS } from './consts'
[test:unit ]
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/util.js:3:21)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/base.js:3:24)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/constants.js:4:14)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/index.js:7:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multihashes/src/index.js:6:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/cids/src/index.js:3:12)
[test:unit ]       at Object.<anonymous> (src/bundles/files/actions.js:10:1)
[test:unit ]       at Object.<anonymous> (src/bundles/files/index.js:4:1)
[test:unit ]       at Object.<anonymous> (src/bundles/notify.js:3:1)
[test:unit ]       at Object.<anonymous> (src/bundles/notify.test.js:3:1)
[test:unit ]
[test:unit ] FAIL src/bundles/analytics.test.js
[test:unit ]   ● Test suite failed to run
[test:unit ]
[test:unit ]     ReferenceError: TextDecoder is not defined
[test:unit ]
[test:unit ]     > 1 | import multiaddr from 'multiaddr'
[test:unit ]         | ^
[test:unit ]       2 | import HttpClient from 'ipfs-http-client'
[test:unit ]       3 | // @ts-ignore
[test:unit ]       4 | import { getIpfs, providers } from 'ipfs-provider'
[test:unit ]
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/util.js:3:21)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/base.js:3:24)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/constants.js:4:14)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multibase/src/index.js:7:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/multihashes/src/index.js:6:19)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected]/node_modules/cids/src/index.js:3:12)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected][email protected]/node_modules/multiaddr/src/convert.js:5:13)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected][email protected]/node_modules/multiaddr/src/codec.js:3:17)
[test:unit ]       at Object.<anonymous> (node_modules/.pnpm/[email protected][email protected]/node_modules/multiaddr/src/index.js:3:15)
[test:unit ]       at Object.<anonymous> (src/bundles/ipfs-provider.js:1:1)
[test:unit ]       at Object.<anonymous> (src/bundles/analytics.js:10:1)
[test:unit ]       at Object.<anonymous> (src/bundles/analytics.test.js:3:1)
[test:unit ]
[test:unit ] Test Suites: 4 failed, 1 skipped, 6 passed, 10 of 11 total
[test:unit ] Tests:       4 skipped, 35 passed, 39 total
[test:unit ] Snapshots:   0 total
[test:unit ] Time:        3.02 s
[test:unit ] Ran all test suites.
[test:unit ]  ELIFECYCLE  Command failed with exit code 1.

What is the fix for this?

SgtPooki avatar Jul 20 '22 20:07 SgtPooki

This may be related to your use of JSDom in the test execution: https://github.com/jsdom/jsdom/issues/2524

achingbrain avatar Jul 20 '22 22:07 achingbrain

js-ipfs is being deprecated in favor of Helia. You can https://github.com/ipfs/js-ipfs/issues/4336 and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterward (see https://github.com/ipfs/js-ipfs/issues/4336).

FYI, my previous issue was resolved with a jsdom global setup file.

SgtPooki avatar May 26 '23 19:05 SgtPooki