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

2

14

I ran anchor test --skip-deploy and all it should do is initialize my program, but all I get is this error, that I cannot resolve. I checked the tsconfig.json settings they should be fine. This is just the default anchor setup and I'm not importing any unusual JSON files anywhere.

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.

Berlyn answered 15/2, 2022 at 0:13 Comment(0)
B
41

I fixed my own problem by running

yarn add ts-mocha

Berlyn answered 16/2, 2022 at 14:21 Comment(2)
Seems to be a version problem. Anchor init uses 8.0.0 and after doing this, updates to 10.0.0Manson
If using a dependency management tool for a monorepo (such as lerna), use yarn add ts-mocha -W instead.Ahimsa
S
0
yarn add ts-mocha

This did not work for me. I deleted the package-lock.json and then updated the npm packages to the latest

"devDependencies": {
    "@types/chai": "^4.3.4",
    "@types/mocha": "^10.0.1",
    "@types/node": "^18.11.18",
    "chai": "^4.3.7",
    "mocha": "^10.2.0",
    "ts-mocha": "^10.0.0",
    "typescript": "^4.9.5"

then updated the provider code:

import * as anchor from "@project-serum/anchor";

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
Senior answered 31/1, 2023 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.