Skip to content

SyntaxError: Cannot use import statement outside a module #138

@kroggen

Description

@kroggen

I am getting this error:

import { AergoClient, GrpcProvider } from '@herajs/client';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

when running a simple script:

import { AergoClient, GrpcProvider } from '@herajs/client';

const aergo = new AergoClient({}, new GrpcProvider({url: 'testnet-api.aergo.io:7845'}));

async function update() {
    const blockchainState = await aergo.blockchain();
    console.log(blockchainState.bestHeight, blockchainState.bestBlockHash);
    setTimeout(update, 3000);
}
update();

The same error with node 14 and 16, tested on Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions