SyntaxError: Unexpected token 'export' when importing @1inch/cross-chain-sdk in Node.js
Description
I encountered issues when trying to use @1inch/cross-chain-sdk in my project. Below are the steps and errors for two different import approaches.
Attempt 1:
Using named imports:
import { SDK } from '@1inch/cross-chain-sdk';
Result:
file:///Users/wildlifechorus/Projects/tangany-circle/index.js:2
import { SDK } from '@1inch/cross-chain-sdk';
^^^
SyntaxError: Named export 'SDK' not found. The requested module '@1inch/cross-chain-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 '@1inch/cross-chain-sdk';
const { SDK } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
Attempt 2:
Switching to a default import with destructuring:
import pkg from '@1inch/cross-chain-sdk';
const { SDK } = pkg;
Result:
(node:4924) 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/wildlifechorus/Projects/tangany-circle/node_modules/@1inch/cross-chain-sdk/dist/esm/index.js:1
export { Address, NetworkEnum, MakerTraits, Extension, AuctionDetails, SettlementPostInteractionData, Interaction, AuctionCalculator,
^^^^^^
SyntaxError: Unexpected token 'export'
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.16.0
Steps to Reproduce
Install the package:
npm install @1inch/cross-chain-sdk
Attempt the following imports:
First Attempt:
import { SDK } from '@1inch/cross-chain-sdk';
Second Attempt:
import pkg from '@1inch/cross-chain-sdk';
const { SDK } = pkg;
Run the file with:
node index.js
Expected Behavior
The package should work seamlessly in Node.js without requiring additional configurations.
Actual Behavior
Both import approaches failed with the errors mentioned above.
Environment
Node.js version: 18.16.0
@1inch/cross-chain-sdk version: 0.1.10
OS: macOS
Additional Notes
I also tried the following workarounds:
Setting "type": "module" in package.json.
Renaming the file to index.mjs.
However, these changes introduced other compatibility issues in my project setup.
Suggested Fix
Please ensure that the package is compatible with both CommonJS and ES module environments. This could include providing proper dual exports or clear documentation on how to configure Node.js projects to use this package.
SyntaxError: Unexpected token 'export'
when importing@1inch/cross-chain-sdk
in Node.jsDescription
I encountered issues when trying to use
@1inch/cross-chain-sdk
in my project. Below are the steps and errors for two different import approaches.Attempt 1:
Using named imports:
Result:
Attempt 2:
Switching to a default import with destructuring:
Result:
Steps to Reproduce
First Attempt:
Second Attempt:
Expected Behavior
The package should work seamlessly in Node.js without requiring additional configurations.
Actual Behavior
Both import approaches failed with the errors mentioned above.
Environment
@1inch/cross-chain-sdk
version: 0.1.10Additional Notes
I also tried the following workarounds:
"type": "module"
inpackage.json
.index.mjs
.However, these changes introduced other compatibility issues in my project setup.
Suggested Fix
Please ensure that the package is compatible with both CommonJS and ES module environments. This could include providing proper dual exports or clear documentation on how to configure Node.js projects to use this package.