Concordium / concordium-browser-wallet

Apache License 2.0
11 stars 9 forks source link

Syntax error: Unexpected token 'export' and can't resolve '@concordium/web-sdk' #328

Closed ghost closed 1 year ago

ghost commented 1 year ago

Bug Description

I have an react application in which I've implemented concordium sdk it was working well but when I have started migrating it to nextjs it is not working and it throws a error called Syntax Error: Unexpected token 'export' for concordium/browser-wallet-api-helpers package and can't resolve '@concordium/web-sdk' for @concordium/web-sdk package

29aba9b1ef3c9130c3930cb0d2a6de33c383df65

82e7ba2d3f720e83e8c9138dc046675f055b89a8

soerenbf commented 1 year ago

This is most likely due to @concordium/web-sdk using browser only functionality, and nextJS does server side rendering of client-side apps.

Long story short, you should be able to resolve this by resolving @concordium/web-sdk as @concordium/node-sdk in the webpack config section of your next.config.js (see their docs).

The configuration would be something like:

if (isServer) {
  webpack.resolve.alias['@concordium/web-sdk'] = '@concordium/node-sdk';
}

We have plans to make the @concordium/web-sdk package compatible with server-side rendering, though it's not certain when this will be available. For now the workaround described above should help.

soerenbf commented 1 year ago

A side note, this should have nothing to do with the browser wallet repository though. But as I wrote in my previous comment, we are aware of the inconvenience of having to do this workaround, so if the workaround works there is no need to create an issue for this.

For reference, here is the issue: https://github.com/Concordium/concordium-node-sdk-js/issues/112

shjortConcordium commented 1 year ago

Nothing to do with the wallet.