Solana 测试程序锚点测试失败 tsconfig.json" > 需要类型 "json" 的导入断言

Solana Test Program Anchor Test failing tsconfig.json" > needs an import assertion of type "json"

I 运行 anchor test --skip-deploy 它应该做的就是初始化我的程序,但我得到的只是这个错误,我无法解决。我检查了 tsconfig.json 设置,它们应该没问题。这只是最默认的锚点设置,我不会在任何地方导入任何不寻常的 json 文件。

anchor test --skip-deploy BPF SDK: /Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf cargo-build-bpf child: rustup toolchain list -v cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release warning: unused variable: ctx --> programs/feeRedeemCounter/src/lib.rs:8:23 | 8 | pub fn initialize(ctx: Context) -> ProgramResult { | ^^^ help: if this is intentional, prefix it with an underscore: _ctx | = note: #[warn(unused_variables)] on by default

warning: feeRedeemCounter (lib) generated 1 warning Finished release [optimized] target(s) in 1.28s cargo-build-bpf child: /Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so

To deploy this program: $ solana program deploy /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so The program address will default to this keypair (override with --program-id): /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter-keypair.json yarn run v1.22.17 warning package.json: No license field $ /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'

TypeError: Module "file:///Users/julia/Downloads/anchorTutorial/feeRedeemCounter/tsconfig.json" needs an import assertion of type "json" at new NodeError (node:internal/errors:371:5) at validateAssertions (node:internal/modules/esm/assert:82:15) at defaultLoad (node:internal/modules/esm/load:24:3) at ESMLoader.load (node:internal/modules/esm/loader:359:26) at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58) at new ModuleJob (node:internal/modules/esm/module_job:66:26) at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34) at async Promise.all (index 0) at ESMLoader.import (node:internal/modules/esm/loader:337:24) at importModuleDynamicallyWrapper (node:internal/vm/module:437:15) at formattedImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:7:14) at Object.exports.requireOrImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:48:32) at Object.exports.loadFilesAsync (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:103:20) at singleRun (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run-helpers.js:125:3) at Object.exports.handler (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run.js:374:5) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Error: Program address not found.

我通过 运行

解决了我自己的问题

yarn add ts-mocha