【问题标题】:You may need an appropriate loader to handle this file type - React你可能需要一个合适的加载器来处理这个文件类型——React
【发布时间】:2021-10-11 19:22:14
【问题描述】:

您好,我正在使用 React 做区块链,但是当我使用导入 Web 3 时

import Web3 from 'web3'

它给了我这个错误:

./node_modules/web3-eth-accounts/lib/index.js
Module parse failed: Unexpected token (225:12)
You may need an appropriate loader to handle this file type.
|         }
|         return signed({
|             ...tx,
|             chainId: args[0],

我正在使用节点 14.17.1,并且我使用此节点创建了它

create-react-app my-app --scripts-version 1.1.5

我安装了 web3 使用

npm install web3

这是 tsconfig.json 文件,这个文件也显示错误

{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
      "outDir": "./lib",
      "esModuleInterop": true
    },
    "include": [
      "./src"
    ]
   }

以及错误所指的 index.js 代码

return signed({
            ...tx,
            chainId: args[0],
            nonce: args[1],
            networkId: args[2],
            ...args[3] // Will either be gasPrice or maxFeePerGas and maxPriorityFeePerGas
        });

【问题讨论】:

  • 您使用的是哪个版本的 Node?您使用的是什么构建器? And remember to put that in your post.
  • 14.17.1 @Mike'Pomax'Kamermans
  • 我使用 npm install --save web3 安装了 web 3
  • 不,真的,将这些详细信息放在您的帖子中 [根据发布指南](/help/how-to-ask)。如果您使用的是打字稿,Node 就无法在本机上运行它。那么你还用什么来让 Node 运行你的代码呢?再次记住,不要告诉我,而是将这些信息放在您的帖子中告诉每个人

标签: reactjs web3


【解决方案1】:

你的项目是用--scripts-version 1.1.5创建的,这意味着它的babel不能解析...,考虑使用更高的scripts-version。对我来说,我从1.1.4升级到3.2.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-19
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2016-09-28
    相关资源
    最近更新 更多