Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anchor test failed with TSError: ⨯ Unable to compile TypeScript #3548

Open
manxiaqu opened this issue Feb 10, 2025 · 0 comments
Open

anchor test failed with TSError: ⨯ Unable to compile TypeScript #3548

manxiaqu opened this issue Feb 10, 2025 · 0 comments

Comments

@manxiaqu
Copy link

I'm following the example on https://solana.com/zh/docs/intro/installation#install-the-solana-cli. All works well before anchor test.

error of anchor test, the project is just created by anchor init my-project:

Found a 'test' script in the Anchor.toml. Running it as a test suite!

Running test suite: "/Users/hao/git/my-project/Anchor.toml"

yarn run v1.22.5
warning ../package.json: No license field
$ /Users/hao/git/my-project/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
Warning: Cannot find any files matching pattern "./test/**/*.spec.ts"

TSError: ⨯ Unable to compile TypeScript:
tests/my-project.ts(34,23): error TS2304: Cannot find name 'exports'.
tests/my-project.ts(35,29): error TS2591: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
tests/my-project.ts(43,9): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.

    at createTSError (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:261:12)
    at getOutput (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:367:40)
    at Object.compile (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:558:11)
    at Module.m._compile (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:439:43)
    at Module.m._compile (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:439:23)
    at loadTS (node:internal/modules/cjs/loader:1815:10)
    at require.extensions.<computed> (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:442:12)
    at Object.require.extensions.<computed> [as .ts] (/Users/hao/git/my-project/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (node:internal/modules/cjs/loader:1458:32)
    at Function._load (node:internal/modules/cjs/loader:1275:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
    at Module.require (node:internal/modules/cjs/loader:1480:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.exports.requireOrImport (/Users/hao/git/my-project/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
    at Object.exports.loadFilesAsync (/Users/hao/git/my-project/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
    at singleRun (/Users/hao/git/my-project/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/Users/hao/git/my-project/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.

I have tried to install type script env using cmd follows, but it didn't work.

npm install ts-node --save-dev
npm install typescript -g 
npm install typescript --save-dev

node version: v23.7.0
solana version: solana-cli 2.1.14 (src:035c4eb0; feat:3271415109, client:Agave)
anchor version: anchor-cli 0.30.1

How can I fix the problem and run anchor test success?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant