Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

ReferenceError: TextDecoder is not defined #3620

Closed
ekumahost opened this issue Apr 9, 2021 · 18 comments
Closed

ReferenceError: TextDecoder is not defined #3620

ekumahost opened this issue Apr 9, 2021 · 18 comments
Assignees
Labels
kind/not-helia-issue need/triage Needs initial labeling and prioritization

Comments

@ekumahost
Copy link

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 ekumahost added the need/triage Needs initial labeling and prioritization label Apr 9, 2021
@welcome
Copy link

welcome bot commented Apr 9, 2021

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.

@danielcjacks
Copy link

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

@elmariachi111
Copy link

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

@achingbrain
Copy link
Member

What version of node are you running?

@elmariachi111
Copy link

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

@ekumahost
Copy link
Author

What version of node are you running?

node:10.16.0-alpine [Docker]

@elmariachi111
Copy link

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: Gozala/web-encoding@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...

"multibase": "^4.0.2",

image

@achingbrain
Copy link
Member

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

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

@elmariachi111
Copy link

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

@RomarQ
Copy link

RomarQ commented Apr 10, 2021

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
Copy link

RomarQ commented Apr 10, 2021

A workaround, while it doesn't get fixed:

npm i --save-exact [email protected]

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

@ekumahost
Copy link
Author

@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.

@elmariachi111
Copy link

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)

@ekumahost
Copy link
Author

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

@yus1uf
Copy link

yus1uf commented Sep 12, 2021

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

@SgtPooki
Copy link
Member

SgtPooki commented Jul 20, 2022

@achingbrain This is not working for me in ipfs-webui with node version 16.12.0 when I'm trying to upgrade dependencies: ipfs/ipfs-webui#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 SgtPooki reopened this Jul 20, 2022
@achingbrain
Copy link
Member

This may be related to your use of JSDom in the test execution: jsdom/jsdom#2524

@SgtPooki
Copy link
Member

js-ipfs is being deprecated in favor of Helia. You can #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 #4336).

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/not-helia-issue need/triage Needs initial labeling and prioritization
Projects
No open projects
Status: Done
Development

No branches or pull requests

7 participants