project-serum / sol-wallet-adapter

Other
185 stars 93 forks source link

SyntaxError: Cannot use import statement outside a module #48

Open muhammadaqibmasood opened 2 years ago

muhammadaqibmasood commented 2 years ago

C:\Users\Bloctech\Documents\solana\solr-token-sale\js\node_modules\@project-serum\sol-wallet-adapter\dist\cjs\index.js:79 import EventEmitter from 'eventemitter3'; ^^^^^^

SyntaxError: Cannot use import statement outside a module

lpetkov-sw commented 2 years ago

Hey, I have the same problem. Did you found a solution ? Btw, are you using nextJs ?

caitsithlord commented 2 years ago

Ran into the same issue while using next.js

I was able to resolve it by replacing the lines with common js syntax

import EventEmitter from 'eventemitter3';

with

const EventEmitter = require('eventemitter3');

Doing the same with all imports in the module and replacing export default with module.exports =

was able to resolve the issue for me.

d-x90 commented 2 years ago

If you are using next.js make sure, you don't use anything in global context from @project-serum\sol-wallet-adapter e.g.:

new Wallet("https://www.sollet.io", cluster);

shouldn't be called on top level of your file because next will try to call it on the server-side.

saadjhk commented 1 year ago

Facing this issue as well @d-x90 should we have a "module": "commonjs" in tsconfig.build.json