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

Usage react-scripts tests: TypeError: json.encode is not a function #110

Closed
D4nte opened this issue Jul 30, 2021 · 8 comments
Closed

Usage react-scripts tests: TypeError: json.encode is not a function #110

D4nte opened this issue Jul 30, 2021 · 8 comments
Labels
need/author-input Needs input from the original author

Comments

@D4nte
Copy link

D4nte commented Jul 30, 2021

When trying to use multiformats with react-scripts (jest), I get an odd error:

yarn create react-app multiformats-react
cd multiformats-react
yarn add multiformats

Then, I just add code from the readme in App.js:

function App() {

    useEffect(() => {
        const bytes = json.encode({ hello: 'world' })
        const hash = sha256.digest(bytes).then((hash) => {
            const cid = CID.create(1, json.code, hash)
            console.log(cid.toString(base64.encoder))
        })
    })
	// ...
}

And I am getting the following error when running react-scripts test (uses jest in the background):

yarn test
$ react-scripts test
 FAIL  src/App.test.js
  ✕ renders learn react link (89 ms)

  ● renders learn react link

    TypeError: json.encode is not a function

      12 |
      13 |     useEffect(() => {
    > 14 |         const bytes = json.encode({ hello: 'world' })
         |                            ^
      15 |         const hash = sha256.digest(bytes).then((hash) => {
      16 |             const cid = CID.create(1, json.code, hash)
      17 |             console.log(cid.toString(base64.encoder))

      at src/App.js:14:28
      at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:318:25)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31)
      at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9)
      at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12)
      at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
      at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14)
      at Object.<anonymous>.flushWork (node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
      at render (node_modules/@testing-library/react/dist/pure.js:97:26)
      at Object.<anonymous> (src/App.test.js:5:3)

  console.error
    Error: Uncaught [TypeError: json.encode is not a function]
        at reportException (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
        at innerInvokeEventListeners (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:333:9)
        at invokeEventListeners (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
        at HTMLUnknownElementImpl._dispatch (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
        at HTMLUnknownElementImpl.dispatchEvent (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLUnknownElement.dispatchEvent (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
        at Object.invokeGuardedCallbackDev (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
        at invokeGuardedCallback (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
        at flushPassiveEffectsImpl (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:23574:9)
        at unstable_runWithPriority (/home/froyer/src/multiformat-react/node_modules/scheduler/cjs/scheduler.development.js:468:12) TypeError: json.encode is not a function
        at /home/froyer/src/multiformat-react/src/App.js:14:28
        at invokePassiveEffectCreate (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:23487:20)
        at HTMLUnknownElement.callCallback (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:3945:14)
        at HTMLUnknownElement.callTheUserObjectsOperation (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
        at innerInvokeEventListeners (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:318:25)
        at invokeEventListeners (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
        at HTMLUnknownElementImpl._dispatch (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
        at HTMLUnknownElementImpl.dispatchEvent (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLUnknownElement.dispatchEvent (/home/froyer/src/multiformat-react/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
        at Object.invokeGuardedCallbackDev (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
        at invokeGuardedCallback (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
        at flushPassiveEffectsImpl (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:23574:9)
        at unstable_runWithPriority (/home/froyer/src/multiformat-react/node_modules/scheduler/cjs/scheduler.development.js:468:12)
        at runWithPriority$1 (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
        at flushPassiveEffects (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
        at Object.<anonymous>.flushWork (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
        at act (/home/froyer/src/multiformat-react/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
        at render (/home/froyer/src/multiformat-react/node_modules/@testing-library/react/dist/pure.js:97:26)
        at Object.<anonymous> (/home/froyer/src/multiformat-react/src/App.test.js:5:3)
        at Promise.then.completed (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/utils.js:276:28)
        at new Promise (<anonymous>)
        at callAsyncCircusFn (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/utils.js:216:10)
        at _callCircusTest (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/run.js:212:40)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at _runTest (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/run.js:149:3)
        at _runTestsForDescribeBlock (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/run.js:63:9)
        at run (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/run.js:25:3)
        at runAndTransformResultsToJestFormat (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:176:21)
        at jestAdapter (/home/froyer/src/multiformat-react/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:109:19)
        at runTestInternal (/home/froyer/src/multiformat-react/node_modules/jest-runner/build/runTest.js:380:16)
        at runTest (/home/froyer/src/multiformat-react/node_modules/jest-runner/build/runTest.js:472:34)
        at Object.worker (/home/froyer/src/multiformat-react/node_modules/jest-runner/build/testWorker.js:133:12)

      at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:28)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:333:9)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)

  console.error
    The above error occurred in the <App> component:
    
        at App (/home/froyer/src/multiformat-react/src/App.js:13:5)
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

      at logCapturedError (node_modules/react-dom/cjs/react-dom.development.js:20085:23)
      at update.callback (node_modules/react-dom/cjs/react-dom.development.js:20118:5)
      at callCallback (node_modules/react-dom/cjs/react-dom.development.js:12318:12)
      at commitUpdateQueue (node_modules/react-dom/cjs/react-dom.development.js:12339:9)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:20736:11)
      at commitLayoutEffects (node_modules/react-dom/cjs/react-dom.development.js:23426:7)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.566 s, estimated 4 s
Ran all test suites related to changed files.
@rvagg
Copy link
Member

rvagg commented Jul 30, 2021

What does your import/require look like for json? It should be import * as json from 'multiformats/codecs/json', or const json = require('multiformats/codecs/json').

You also may want to consider using https://github.com/ipld/js-dag-json if you want deterministic encoding and the ability to encode links and bytes too.

@lidel lidel added the need/author-input Needs input from the original author label Jul 30, 2021
@D4nte
Copy link
Author

D4nte commented Aug 1, 2021

What does your import/require look like for json? It should be import * as json from 'multiformats/codecs/json', or const json = require('multiformats/codecs/json').

You also may want to consider using ipld/js-dag-json if you want deterministic encoding and the ability to encode links and bytes too.

Thank you for reviewing my issue.

I can confirmed I tried both method of import and in both cases the issue occurs.

I am starting to understand that react-scripts uses Jest that uses jsdom, could this be related?

I actually uses libp2p and encounter this issue: libp2p/js-libp2p#961 so I thought I'd isolate the multiformats library and see if I can make it work with react-scripts, which is not the case, hence the current issue being opened :)

@rvagg
Copy link
Member

rvagg commented Aug 2, 2021

Ahhh jest, yeah, jest does its own thing because it still uses browser-resolve which still doesn't have export maps support.

See jestjs/jest#9771 (comment) for my proposed solution to this, scroll down to other people's iterations on the pattern that works for them. I implemented this in https://github.com/ceramicnetwork/js-dag-jose which uses jest and builds on js-multiformats.

@achingbrain has a possible solution that I think is making its way through our toolchains that may make this go away, I think. I hope that helps.

@D4nte
Copy link
Author

D4nte commented Aug 2, 2021

Oh, thanks! unfortunately react-scripts does not allow the override of the resolver jest config parameter. Which means I'd need to eject the react environment.

It looks like I need to do more investigation on react-scripts side.

D4nte added a commit to waku-org/js-waku that referenced this issue Aug 9, 2021
Unfortunately, there are issue with react-scripts (jest) and
multiformats: multiformats/js-multiformats#110
D4nte added a commit to waku-org/js-waku that referenced this issue Aug 9, 2021
Unfortunately, there are issue with react-scripts (jest) and
multiformats: multiformats/js-multiformats#110
@lidel
Copy link
Member

lidel commented Aug 13, 2021

@D4nte we discussed this during triage and some relevant changes could land in past two weeks – mind updating to the latest version and confirm if the issue is still there?

@D4nte
Copy link
Author

D4nte commented Aug 17, 2021

Hi @lidel. Thanks for that. Unfortunately the error still occurs on a fresh repo with [email protected]

Could it be because react-scripts uses Webpack 4 and not 5? libp2p/js-libp2p#961 (comment)

import logo from './logo.svg';
import './App.css';
import {useEffect} from 'react';
import {CID} from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import {sha256} from 'multiformats/hashes/sha2'
import {base64} from "multiformats/bases/base64"


function App() {
    useEffect(() => {
        const bytes = json.encode({hello: 'world'})
        const hash = sha256.digest(bytes).then((hash) => {
            const cid = CID.create(1, json.code, hash)
            console.log(cid.toString(base64.encoder))
        })
    })


    return (
        <div className="App">
            <header className="App-header">
                <img src={logo} className="App-logo" alt="logo"/>
                <p>
                    Edit <code>src/App.js</code> and save to reload.
                </p>
                <a
                    className="App-link"
                    href="https://reactjs.org"
                    target="_blank"
                    rel="noopener noreferrer"
                >
                    Learn React
                </a>
            </header>
        </div>
    );
}

export default App;

Gives me

/usr/bin/node /home/froyer/.node_modules/lib/node_modules/yarn/bin/yarn.js test
yarn run v1.22.11
$ react-scripts test
 FAIL  src/App.test.js
  ✕ renders learn react link (225 ms)

  ● renders learn react link

    TypeError: json.encode is not a function

      10 | function App() {
      11 |     useEffect(() => {
    > 12 |         const bytes = json.encode({hello: 'world'})
         |                            ^
      13 |         const hash = sha256.digest(bytes).then((hash) => {
      14 |             const cid = CID.create(1, json.code, hash)
      15 |             console.log(cid.toString(base64.encoder))

      at src/App.js:12:28
      at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31)
      at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9)
      at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12)
      at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
      at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14)
      at Object.<anonymous>.flushWork (node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
      at render (node_modules/@testing-library/react/dist/pure.js:97:26)
      at Object.<anonymous> (src/App.test.js:5:3)

  console.error
    Error: Uncaught [TypeError: json.encode is not a function]
        at reportException (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
        at innerInvokeEventListeners (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:341:9)
        at invokeEventListeners (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
        at HTMLUnknownElementImpl._dispatch (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
        at HTMLUnknownElementImpl.dispatchEvent (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLUnknownElement.dispatchEvent (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
        at Object.invokeGuardedCallbackDev (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
        at invokeGuardedCallback (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
        at flushPassiveEffectsImpl (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:23574:9)
        at unstable_runWithPriority (/home/froyer/src/react-next-libp2p/node_modules/scheduler/cjs/scheduler.development.js:468:12) TypeError: json.encode is not a function
        at /home/froyer/src/react-next-libp2p/src/App.js:12:28
        at invokePassiveEffectCreate (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:23487:20)
        at HTMLUnknownElement.callCallback (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:3945:14)
        at HTMLUnknownElement.callTheUserObjectsOperation (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
        at innerInvokeEventListeners (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
        at invokeEventListeners (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
        at HTMLUnknownElementImpl._dispatch (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
        at HTMLUnknownElementImpl.dispatchEvent (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLUnknownElement.dispatchEvent (/home/froyer/src/react-next-libp2p/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
        at Object.invokeGuardedCallbackDev (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
        at invokeGuardedCallback (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
        at flushPassiveEffectsImpl (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:23574:9)
        at unstable_runWithPriority (/home/froyer/src/react-next-libp2p/node_modules/scheduler/cjs/scheduler.development.js:468:12)
        at runWithPriority$1 (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
        at flushPassiveEffects (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
        at Object.<anonymous>.flushWork (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
        at act (/home/froyer/src/react-next-libp2p/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
        at render (/home/froyer/src/react-next-libp2p/node_modules/@testing-library/react/dist/pure.js:97:26)
        at Object.<anonymous> (/home/froyer/src/react-next-libp2p/src/App.test.js:5:3)
        at Promise.then.completed (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/utils.js:276:28)
        at new Promise (<anonymous>)
        at callAsyncCircusFn (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/utils.js:216:10)
        at _callCircusTest (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/run.js:212:40)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at _runTest (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/run.js:149:3)
        at _runTestsForDescribeBlock (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/run.js:63:9)
        at run (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/run.js:25:3)
        at runAndTransformResultsToJestFormat (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:176:21)
        at jestAdapter (/home/froyer/src/react-next-libp2p/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:109:19)
        at runTestInternal (/home/froyer/src/react-next-libp2p/node_modules/jest-runner/build/runTest.js:380:16)
        at runTest (/home/froyer/src/react-next-libp2p/node_modules/jest-runner/build/runTest.js:472:34)
        at Object.worker (/home/froyer/src/react-next-libp2p/node_modules/jest-runner/build/testWorker.js:133:12)

      at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:70:28)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:341:9)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)

  console.error
    The above error occurred in the <App> component:
    
        at App (/home/froyer/src/react-next-libp2p/src/App.js:11:5)
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

      at logCapturedError (node_modules/react-dom/cjs/react-dom.development.js:20085:23)
      at update.callback (node_modules/react-dom/cjs/react-dom.development.js:20118:5)
      at callCallback (node_modules/react-dom/cjs/react-dom.development.js:12318:12)
      at commitUpdateQueue (node_modules/react-dom/cjs/react-dom.development.js:12339:9)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:20736:11)
      at commitLayoutEffects (node_modules/react-dom/cjs/react-dom.development.js:23426:7)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        4.046 s
Ran all test suites related to changed files.

@rvagg
Copy link
Member

rvagg commented Aug 19, 2021

It should be fine with webpack 4, even our tests in this repo use webpack 4 for some browser testing.

What happens if you switch it out for dag-json? npm install @ipld/dag-json and use import * as dagJSON from '@ipld/dag-json, replacing json in your code with dagJSON? Maybe you don't want dag-json but need the actual json multicodec in your CID but it'd be interesting to see if this makes a difference, in theory they should be the same under the hood but if that works and your json doesn't then that might tell us something.

I don't really know anything about react-scripts but I see mention of jest in here, which is a long-standing problem child for us because of its continued lack of support for export maps. Have a look at this jestjs/jest#9771 (comment), and then below that there's some iterations on the idea. If you look at https://github.com/ceramicnetwork/js-dag-jose you'll see that it uses jest for testing but I was able to use this module loader replacement to make it work properly.

@D4nte
Copy link
Author

D4nte commented Aug 19, 2021

Hi @rvagg, thanks for that. React-scripts uses jest and indeed, jestjs/jest#9771 (comment) might be the solution but it is not something that can be configured in react-scripts.

I think you found out the issue. Not really something that can be resolved by js-multiformats so closing or now. I have to use another test framework than react-scripts.

@D4nte D4nte closed this as completed Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/author-input Needs input from the original author
Projects
None yet
Development

No branches or pull requests

3 participants