javascript - 模块解析失败:React 项目中出现意外的令牌。您可能需要适当的加载程序来处理此文件类型
问题描述
我是 React 的新手,所以如果这是一个非常愚蠢和明显的错误,我提前道歉。
我正在尝试为简单的区块链文件传输创建去中心化应用程序(DApp)。我正在关注以下教程:https ://itnext.io/build-a-simple-ethereum-interplanetary-file-system-ipfs-react-js-dapp-23ff4914ce4e (tl;dr 版本 - 基本上是文件传输区块链网络。您将文件上传到 IPFS,然后将 IPFS 位置从一个区块链帐户发送到另一个)。对于前端,我使用的是 React。
有两点需要注意——
1. 我使用的是 Ropsten 网络,而不是本文中使用的 Rinkeby
2. 在 REMIX 中,我将部署环境设置为“Injected Web3”。(原始项目模棱两可)
此项目的依赖项之一是ipfs-api
,但现在已弃用。所以我不得不ipfs-http-client
改用。npm 安装成功。然而,在编译时,我得到了错误
./node_modules/ipfs-http-client/src/lib/to-url-search-params.js
Module parse failed: Unexpected token (10:61)
You may need an appropriate loader to handle this file type.
| * @returns {URLSearchParams}
| */
| module.exports = ({ arg, searchParams, hashAlg, mtime, mode, ...options } = {}) => {
| if (searchParams) {
| options = {
to-url-search-params.js 文件 -
'use strict'
const modeToString = require('./mode-to-string')
const { parseMtime } = require('ipfs-unixfs')
/**
* @param {*} params
* @returns {URLSearchParams}
*/
module.exports = ({ arg, searchParams, hashAlg, mtime, mode, ...options } = {}) => {
if (searchParams) {
options = {
...options,
...searchParams
}
}
if (hashAlg) {
options.hash = hashAlg
}
if (mtime != null) {
mtime = parseMtime(mtime)
options.mtime = mtime.secs
options.mtimeNsecs = mtime.nsecs
}
if (mode != null) {
options.mode = modeToString(mode)
}
if (options.timeout && !isNaN(options.timeout)) {
// server API expects timeouts as strings
options.timeout = `${options.timeout}ms`
}
if (arg === undefined || arg === null) {
arg = []
} else if (!Array.isArray(arg)) {
arg = [arg]
}
const urlSearchParams = new URLSearchParams(options)
arg.forEach((/** @type {any} */ arg) => urlSearchParams.append('arg', arg))
return urlSearchParams
}
所有其他文件与https://github.com/mcchan1/eth-ipfs中提供的文件完全相同。
不知道错误是什么......提前感谢您的帮助。
解决方案
推荐阅读
- javascript - 数据索引 NodeList.Foreach JavaScript
- python - pandas:将 100 多个变量融合到 100 多个新数据帧中
- javascript - 函数内部的全局变量不能在外部访问
- sql - Q. 如何从 XSD 字符串字段中选择命名元素值
- python - 为什么在这种情况下,在 Django 中,views.py 中的函数需要请求参数?
- c - 如何在不使用 c 中的任何递归函数的情况下遍历目录?
- c++ - 如何在 C++ 函数中移动变量
- python - 检查字符串中每一行的前几位,如果它们相等,则将这些行的一部分一起打印
- angular - 如何在链式可观察对象之间传递结果
- python - Django WSGI 在管理员中保存模型选择字段时出错