Anchor Test Error: TypeError: Cannot read properties of undefined (reading ‘local’)

I am current trying to build a solana calculator project on my mac(M3 version), mostly duplicate the code what I learned on Udemy. So basically I am trying run the same of the teacher on my pc successfully.

What i use:
Anchor
Mocha
node_modules/@project-serum
solana

What I did:

  1. use anchor init to create a project
  2. anchor build(i can build without errors)
  3. Add some code to lib.rs file:
    use anchor_lang::prelude::*;

    declare_id!("CfaDqW3stWavnEn8KZLnqSLbmTzUjhn3aNawSCtsVbGu");

    #[program]
    pub mod mycalculatordapp {
        use super::*;
        pub fn create(ctx: Context<Create>, init_message: String) -> Result<()> {
            let calculator = &mut ctx.accounts.calculator;
            calculator.greeting = init_message;
            Ok(())
        }
     }

    #[derive(Accounts)]
    pub struct Create<'info>{
        #[account(init, payer=user, space=264)]
        pub calculator: Account<'info, Calculator>,
        #[account(mut)]
       pub user: Signer<'info>,
       pub system_program: Program<'info, System>
    }

    #[account]
    pub struct Calculator {
        pub greeting: String,
        pub result: i64,
        pub remainder: i64
    }
  1. Add a simple test code to mycalculatordapp.ts file:
const assert = require('assert');
const anchor = require('@project-serum/anchor');
const { SystemProgram } = anchor.web3;

describe('mycalculatordapp', () => {
  const provider = anchor.Provider.local();
});

And then I got this Error when I run ‘anchor test’ on my terminal:

TypeError: Cannot read properties of undefined (reading ‘local’)
at Suite. (/Users/chester/Desktop/dev/mycalculatordapp/tests/mycalculatordapp.ts:6:36)
at Object.create (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object. (/Users/chester/Desktop/dev/mycalculatordapp/tests/mycalculatordapp.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module.m._compile (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Object.require.extensions. [as .ts] (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/ts-node/src/index.ts:442:12)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Function.Module._load (node:internal/modules/cjs/loader:1022:12)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object.exports.requireOrImport (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
at Object.exports.loadFilesAsync (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
at singleRun (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/Users/chester/Desktop/dev/mycalculatordapp/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.

I have tried my ways but just can’t not solve this issue, hope some professionals can take a look and give me a insight.

I have check all the dependencies, which should be installed correctly. The problem will be very likely to caused by this line:

const provider = anchor.Provider.local();

I am not sure is there a environmental set up error of any other issue, just can’t pass this.

New contributor

Chester H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật