TypeError:Solana Anchor 项目中存在未知文件扩展名“.ts”

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

将 Solana-cli 更新到 1.9.4 并将 Anchor-cli 更新到 0.20.1 和其他本地 npm 版本后,我收到此错误...

% anchor test
....

TypeError: Unknown file extension ".ts" for /Users/me/Code/solana/myapp/tests/myapp.ts

我的系统的详细信息

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 [脚本]命令: 该命令在其他存储库中运行良好:

test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

问题是m1.ts文件无法从另一个ts文件导入函数!!!???

在我的 utils.ts 中

export const log1 = console.log;

在我的 m1 文件中:

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

导入的log1函数或任何其他函数将导致未知文件扩展名“.ts”错误!!???

我的本地包依赖项:

"mocha": "^9.1.3",
"ts-mocha": "^9.0.0-alpha1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"

请指教。谢谢你

typescript mocha.js blockchain smartcontracts solana
1个回答
1
投票

由于测试命令适用于其他存储库,这意味着您的系统中已经有

yarn
ts-node

tsconfig.json 文件 config.json 应该是这样的:

{
  "compilerOptions": {
    "types": ["mocha", "chai"],
    "typeRoots": ["./node_modules/@types"],
    "lib": ["es2015"],
    "module": "commonjs",
    "target": "es6",
    "esModuleInterop": true
  }
}

由于您要导入文件,因此必须设置

"esModuleInterop": true
。这允许从模块推断类型。

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