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

"Cannot use import statement outside a module" error when using ontology-ts-sdk (@vespaiach/axios-fetch-adapter/index.js) #237

Open
sinanouri opened this issue May 30, 2024 · 0 comments

Comments

@sinanouri
Copy link

sinanouri commented May 30, 2024

When attempting to use the ontology-ts-sdk library in a Node.js environment, I encountered the error "Cannot use import statement outside a module." This error seems to be related to the library's internal usage of ES module syntax (import statements) conflicting with the CommonJS syntax used in Node.js environments.

Steps to Reproduce:

  1. Include the following code in app.js:
const {
  Account,
  Crypto,
  OntAssetTxBuilder,
  TransactionBuilder,
  RestClient,
  CONST,
} = require("ontology-ts-sdk");
console.log("ontology sdk");
  1. Install the ontology-ts-sdk library via npm:
npm install ontology-ts-sdk
  1. Run the application:
node app.js

Expected Behavior:
The application should run without errors, and the message "ontology sdk" should be logged to the console.

Actual Behavior:
The application throws a SyntaxError: "Cannot use import statement outside a module" at @vespaiach/axios-fetch-adapter/index.js.

Environment:

  • Node.js version: v18.19.0
  • ontology-ts-sdk version: 2.0.3

Package.json:

{
  "dependencies": {
    "ontology-ts-sdk": "^2.0.3"
  }
}

The Error:

/node_modules/@vespaiach/axios-fetch-adapter/index.js:1
import axios from 'axios';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1274:20)
    at Module._compile (node:internal/modules/cjs/loader:1320:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/node_modules/ontology-ts-sdk/lib/index.js:1:2593)
    at r (/node_modules/ontology-ts-sdk/lib/index.js:1:124)

Node.js v18.19.0
@sinanouri sinanouri changed the title "Cannot use import statement outside a module" error when using ontology-ts-sdk "Cannot use import statement outside a module" error when using ontology-ts-sdk (@vespaiach/axios-fetch-adapter/index.js) May 31, 2024
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