sol-wallet-adapter icon indicating copy to clipboard operation
sol-wallet-adapter copied to clipboard

SyntaxError: Cannot use import statement outside a module

Open muhammadaqibmasood opened this issue 3 years ago • 4 comments

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

muhammadaqibmasood avatar Oct 17 '21 12:10 muhammadaqibmasood

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

lpetkov-sw avatar Nov 04 '21 10:11 lpetkov-sw

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.

caitsithlord avatar Nov 29 '21 05:11 caitsithlord

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.

d-x90 avatar Jan 11 '22 13:01 d-x90

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

saadahmsiddiqui avatar Jan 13 '23 09:01 saadahmsiddiqui