0

In the website https://react-typescript-cheatsheet.netlify.app/,I want learn more about the TS,so I want to run the Example code of TS,then I want I can get a result of these Example code,however ,I just get an error .

this is the link of one of the example code of Playground for TS: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCpAD0ljkwFcA7DYCZuRgZyQBkIKACbBmAcwAUASjgBvCnDhoO3eAG1g3AcNFiANHF4wAyjBQwkAXTgBeRMRgA6HklPmkEzCgA2vKQG4FJRV4b0EhWzgJFAAFHBBNJAAuODjcRIAeFGYATwA+GRs8uSDFIzcLCRgoRiQA0rgiGEYoTlj4xMdMUR9vHIlpW2Lys0qvXzr68kUAX0DpxqRm1rgNLXDdAzDhaxRuYOZVfzgAehO4UUwkKH21ACMICG9UZgMYHLAkCEw4baFrUSqVARb5RB5PF5wAA+cHen1BfykaksFBmQA

after I click run,then I get an Error as follow:

[ERR] "Executed JavaScript Failed:"

[ERR]: Cannot use import statement outside a module 

JavaScript language version is ES2020

  • 1
    The error is pretty clear though... you cannot use an `import` statement in the typescript playground. It's better to use codepen or codesandbox for testing react code. – Kokodoko Aug 01 '22 at 09:46
  • Does this answer your question? [Typescript: Cannot use import statement outside a module](https://stackoverflow.com/questions/58273824/typescript-cannot-use-import-statement-outside-a-module) – Ashish Patil Aug 01 '22 at 10:20
  • "Typescript: Cannot use import statement outside a module",this is not solve my question.but I can use codepen or codesandbox to test react code. – LibertyAndHappy Aug 02 '22 at 01:29

1 Answers1

1

I don't think you're reading the instructions carefully enough: the tutorial setup page says 'TypeScript Playground with React: just if you are debugging types (and reporting issues), not for running code' (my emphasis).

The CodeSandbox link on the next line seems to run the code fine with React in the cloud.

Rich N
  • 8,939
  • 3
  • 26
  • 33