simple-dapp-tutorial icon indicating copy to clipboard operation
simple-dapp-tutorial copied to clipboard

Uncaught SyntaxError: Cannot use import statement outside a module

Open SuperCS92 opened this issue 4 years ago • 5 comments

Hello,

Thank you very much for this tutorial. When adding ' import MetaMaskOnboarding from '@metamask/onboarding' on contract.js as appears in the index.js in the finished directory, the console throws this message ' Uncaught SyntaxError: Cannot use import statement outside a module '. It is not a problem with your code, but I can not run the tutorial because of this error. I'm assuming you are not having this problem or you solved it, either way, hope you can help, I don't know if I'm the only one having this problem.

I'm sorry if I'm misusing this channel, is the first issue I report.

SuperCS92 avatar Apr 06 '21 16:04 SuperCS92

Hmmm, I'll check it out! 🙂 Thanks for posting this!

BboyAkers avatar May 09 '21 21:05 BboyAkers

@SuperCS92 I inspected index.html and it looks like the project is importing @metamask/onboarding with the prebuilt ES5 bundle <script src="node_modules/@metamask/onboarding/dist/metamask-onboarding.bundle.js" defer></script>

WHICH means you can use the global variable MetamaskOnboarding without importing it, i.e just do const onboarding = new MetamaskOnboarding({ forwarderOrigin });

Note: the prebuilt es5 bundle defines MetamaskOnboarding with a lower case M, not MetaMaskOnboarding

friendlycharizard avatar May 10 '21 07:05 friendlycharizard

@BboyAkers Maybe change the tutorial to use MetamaskOnboarding instead of MetaMaskOnboarding?

friendlycharizard avatar May 10 '21 07:05 friendlycharizard

@alyforalyssa I'll update it! Thanks!!🚀🚀 🙂

BboyAkers avatar May 10 '21 21:05 BboyAkers

any fix for this yet?

triloconinja avatar May 25 '21 10:05 triloconinja