首页 > 解决方案 > 海洋协议反应教程 npm 启动失败

问题描述

我只是想克隆这个 repo:https ://github.com/oceanprotocol/react-tutorial

当我运行应用程序时,我得到以下堆栈跟踪:

Uncaught TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at Object../node_modules/whatwg-url/dist/utils.js (utils.js:48)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/whatwg-url/dist/URL.js (URL.js:4)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/whatwg-url/webidl2js-wrapper.js (webidl2js-wrapper.js:3)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/whatwg-url/index.js (index.js:3)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/@oceanprotocol/squid/dist/node/aquarius/Aquarius.js (Aquarius.ts:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/@oceanprotocol/squid/dist/node/ocean/Ocean.js (Ocean.ts:11)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/@oceanprotocol/squid/dist/node/squid.js (squid.ts:4)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/index.js (asset.js:54)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (index.js:126)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

我在解开问题的根本原因方面运气不佳,感谢您提供任何帮助!

标签: javascriptreactjswebpackcreate-react-app

解决方案


看起来本教程使用的包现在已删除。(鱿鱼.js )

以及为什么它给出的TypeError原因whatwg-url是 squid.js 的依赖包,并且whatwg-url期望一个对象及其接收未定义或空值。可能是 squid.js 在内部调用了一些外部 url/api 来创建实例。

而不是使用:

import { Ocean } from '@oceanprotocol/squid'.

用这个 :

react-tutorial repo 尚未更新以支持 V3 版本的海洋协议:https ://github.com/oceanprotocol/react-tutorial/issues/14

import { Ocean } from '@oceanprotocol/react'

NPM:npm install @oceanprotocol/react https ://www.npmjs.com/package/@oceanprotocol/react

Github 文档:https ://github.com/oceanprotocol/ocean.js

希望这可以帮助 !!干杯。


推荐阅读