Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Cannot use import statement outside a module: @stellar/wallet-sdk #337

@Tithra

Description

@Tithra

What version are you using?

@stellar/wallet-sdk@0.9.0

What did you do?

I intended to use @stellar/wallet-sdk for securing way to generate and manage Stellar key pairs, sign transactions and interact with the network in my nodejs project with typescript.

This is the simple code structure:

project

  • src
    index.ts
  • package.json
  • tsconfig.json

Inside index.ts file :

import * as wallet from '@stellar/wallet-sdk';

const keyManager = new wallet.KeyManager({
  keyStore: new wallet.KeyManagerPlugins.MemoryKeyStore(),
});
keyManager.registerEncrypter(wallet.KeyManagerPlugins.ScryptEncrypter);

//and more codes

Inside tsconfig.json:

{
  "extends": "@stellar/tsconfig",
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "lib": ["es2015", "dom"],
    "declaration": true,
    "declarationDir": "dist",
    "moduleResolution": "node",
    "allowJs": true,
    "outDir": "dist",
    "rootDir": "src",
    "strict": true,
    "skipLibCheck": true,
    "noEmitOnError": true, //stop ts from build js code when error occurs
    "sourceMap": true, //map ts to js for debuging process
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "noUnusedParameters": false,
    "noUnusedLocals": false,
    "resolveJsonModule": true
  },
  "include": ["src"],
  "exclude": [
    "node_modules",
    "dist",
    "src/browser.ts",
    "playground/src/@stellar",
    "documentation/src/docs.json",
    "src/fixtures"
  ]
}

Inside package.json:

{
  "name": "wellet-sdk",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "commonjs",
  "scripts": {
    "start": "ts-node src/index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^18.14.6",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  },
  "dependencies": {
    "@stellar/freighter-api": "^1.1.2",
    "@stellar/tsconfig": "^1.0.2",
    "@stellar/wallet-sdk": "^0.9.0",
    "stellar-sdk": "^9.0.1"
  }
}

When running, I got this error:

/home/tithra/OtherProjects/Wellet-sdk/node_modules/@stellar/wallet-sdk/dist/index.js:1
import * as Types from "./types";
^^^^^^

SyntaxError: Cannot use import statement outside a module

What did you expect to see?

My goal is to have KeyManager take in the stellar keypairs, encrypt them, and use them for making transactions.

What did you see instead?

I got an error that I can not get through to test the intended features.
Did I miss something here or any other required packages needed for this to work?
I really appreciate your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions