yarn 安全帽测试 -> JSON 输入意外结束

问题描述 投票:0回答:1

我是纱线的新手。之前用npm开发solidity程序。当我尝试使用纱线和

yarn hardhat test
。有错误:

An unexpected error occurred:

SyntaxError: Error parsing /Users/xy/Desktop/program/test_test/node_modules/loupe/package.json: Unexpected end of JSON input
    at parse (<anonymous>)
    at readPackage (node:internal/modules/cjs/loader:304:20)
    at resolveExports (node:internal/modules/cjs/loader:479:15)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/xy/Desktop/program/test_test/node_modules/chai/lib/chai/utils/inspect.js:5:13)
    at Module._compile (node:internal/modules/cjs/loader:1103:14) {
  path: '/Users/xy/Desktop/program/test_test/node_modules/loupe/package.json'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

但是我用的是全新的hardhat demo,

yarn hard compile
没问题。 如果我用
npm

也可以

这是演示脚本:

import { expect } from "chai";
import { ethers } from "hardhat";

describe("Greeter", function () {
  it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello, world!");
    await greeter.deployed();

    expect(await greeter.greet()).to.equal("Hello, world!");

    const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

    // wait until the transaction is mined
    await setGreetingTx.wait();

    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });
});

这似乎是

chai
的问题,因为当我删除
expect
行时问题消失了。

solidity yarnpkg hardhat
1个回答
0
投票

第一步:

奔跑

npx hardhat clean

第二步:

接下来运行它会自动编译

© www.soinside.com 2019 - 2024. All rights reserved.