turbos-finance / turbos-clmm-sdk

6 stars 5 forks source link

SyntaxError: Cannot use import statement outside a module #4

Open alexey-ernest opened 1 year ago

alexey-ernest commented 1 year ago

Hi, when I try to import the sdk into my nodejs module I get the following error:

(node:36564) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/alex/node_modules/turbos-clmm-sdk/dist/esm/index.js:9
import { default as default2 } from "bn.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.15.0

My code is the following:

import pkg from 'turbos-clmm-sdk';
const { Network, TurbosSdk } = pkg;

When I try to import the sdk with the simple import statement "import { Network, TurbosSdk } from 'turbos-clmm-sdk'" like the example from the docs I get this error:

import { Network, TurbosSdk } from 'turbos-clmm-sdk';
         ^^^^^^^
SyntaxError: Named export 'Network' not found. The requested module 'turbos-clmm-sdk' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'turbos-clmm-sdk';
const { Network, TurbosSdk } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.15.0
alexey-ernest commented 1 year ago

Version: "turbos-clmm-sdk": "^0.6.1"

geekact commented 1 year ago

I'm so sorry for what happened on you. Try version 0.7.1 and good luck.