anchor
anchor copied to clipboard
Test generated by anchor init yields error "Provider env is not available on browser."
Description:
The project created from anchor init throws an error when trying to run the generated test.
Reproduction:
anchor init test_project
cd test_project
anchor build
anchor test
Result:
Shows the following error:
BPF SDK: /home/node/.local/share/solana/install/releases/1.8.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/test_project/src/lib.rs:8:23
|
8 | pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
| ^^^ help: if this is intentional, prefix it with an underscore: `_ctx`
|
= note: `#[warn(unused_variables)]` on by default
warning: `test_project` (lib) generated 1 warning
Finished release [optimized] target(s) in 0.12s
cargo-build-bpf child: /home/node/.local/share/solana/install/releases/1.8.5/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /workspaces/dapwords/test_project/target/deploy/test_project.so
To deploy this program:
$ solana program deploy /workspaces/dapwords/test_project/target/deploy/test_project.so
The program address will default to this keypair (override with --program-id):
/workspaces/dapwords/test_project/target/deploy/test_project-keypair.json
yarn run v1.22.15
warning package.json: No license field
$ /workspaces/dapwords/test_project/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
Error: Provider env is not available on browser.
at Function.env (/workspaces/dapwords/test_project/node_modules/@project-serum/anchor/src/provider.ts:68:13)
at Suite.<anonymous> (/workspaces/dapwords/test_project/tests/test_project.ts:8:38)
at Object.create (/workspaces/dapwords/test_project/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/workspaces/dapwords/test_project/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object.<anonymous> (/workspaces/dapwords/test_project/tests/test_project.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module.m._compile (/workspaces/dapwords/test_project/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (/workspaces/dapwords/test_project/node_modules/ts-node/src/index.ts:442:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.exports.requireOrImport (/workspaces/dapwords/test_project/node_modules/mocha/lib/nodejs/esm-utils.js:56:20)
at Object.exports.loadFilesAsync (/workspaces/dapwords/test_project/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
at singleRun (/workspaces/dapwords/test_project/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/workspaces/dapwords/test_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.
Also note that running the tests in the typescript directory in the main repo also has the same failure.
https://github.com/project-serum/anchor/tree/master/tests/typescript
Sorry to bump, but any comment would be appreciated. This is in the main release and a blocker for starting a new project with TypeScript.
Hi managed to figure this out. For me it was the environment variable BROWSER was set to firefox. I cleared this environment variable by doing
export BROWSER=
and this worked
@daniel-lahlafi I cleared this environment variable by doing
export BROWSER=
Would you mind expanding on this? I'm running into the same issue but am not sure where to export BROWSER=
. I've added it to the CLI, like BROWSER= anchor test
, or BROWSER='' anchor test
but neither work.
@daniel-lahlafi I cleared this environment variable by doing
export BROWSER=
Would you mind expanding on this? I'm running into the same issue but am not sure where to
export BROWSER=
. I've added it to the CLI, likeBROWSER= anchor test
, orBROWSER='' anchor test
but neither work.
Just run the command I wrote in the terminal before running anchor
export BROWER= worked just fine here. Thanks !
above comment is missing "S" in BROWSER. export BROWSER= worked fine also here thanks!
In most recent versions of anchor, the exported 'Provider' was moved to 'AnchorProvider'.
Had the same issue, but this was the problem !
a little graceful command:
unset BROWSER
whatever, just make sure BROWSER
environment variable unset then this issue would be fixed. ; )
Error: Provider env is not available on browser.
I have the same error but in my front end anyone one can help me please
BROWSER= anchor test, or BROWSER='' anchor test Thank you. Above command works well.