coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.6k stars 1.32k forks source link

TypeError: Unknown file extension ".ts" #1286

Closed AuroraLantean closed 10 months ago

AuroraLantean commented 2 years ago

I got this error after updating Solana-cli to 1.9.4 and Anchor-cli to 0.20.1 and other local npm versions... please help.

Local npm package: @project-serum/anchor 0.18.2 Solana program dependencies: anchor-lang 0.18.2, anchor-spl 0.18.2, solana-program 1.9.4 Global environment: Rust 1.57.0, solana-cli 1.9.4, @project-serum/anchor-cli 0.20.1

Anchor.toml [script] command: This command works fine at the the other repo: test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

The problem is the m1.ts file cannot import functions from another ts file!!!??? in my utils.ts

export const log1 = console.log;

in my m1 file:

import { log1 } from './utils';
describe('scenario1', async () => {
  it('initialize', async () => {
    log1('\n---------== init');
  });
});

the imported log1 function or any other function will cause the Unknown file extension ".ts" error!!??

my local package dependencies: "mocha": "^9.1.3", "ts-mocha": "^9.0.0-alpha1", "ts-node": "^10.4.0", "typescript": "^4.5.4"

Please advise. Thank you unknown file extension ts2

acheroncrypto commented 10 months ago

This seems to be an issue with ts-mocha as there are lots of comments in https://github.com/piotrwitek/ts-mocha/issues/70. You can use other testing frameworks, Anchor already supports creating projects with jest with anchor init --jest.