How to run/debug scratch file (Javascript/Typescript)

I want to use scratch file as a test polygon. Is it possible to ru a .js/.ts file:

const result = 1 + 1
console.log(result)

Would be fired.

1
10 comments

You can run a JavaScript scratch file using the corresponding action in its right-click menu:

 

 

Typescript scratch files can't be run for the same reason as non-scratch .ts files: Typescript can't be executed directly, it has to be transpiled to JavaScript first

0

Thanks, can i use something like ts-node to run my .ts scratch files?

0

You can try using --require ts-node/register in your run configuration, like:

 

 

of course, you have to install ts-node in your project first

2

Thanks, it works! I also can have `ts-node` installed globally? To remove a need to install it in every project.

0

requiring global modules doesn't usually work, unless you use special tricks like NODE_PATH;

note that requiring global modules is not recommended:

You are highly encouraged to place your dependencies locally in node_modules folders. They will be loaded faster, and more reliably.

0

Just trying to run the file created an SQL run configuration for me. It told me "Error: No configured target data sources", which doesn't make sense.

Instead, I created a local package.json that contained this line, and then I clicked the play button next to that.

"scripts": {    "scratch_javascript": "node scratch_javascript.js"}
1

Same here as Fireslinger

I created a JavaScript scratch file, right-click then run and a dialog saying "No configured target data sources"

Why?

0

2021.3.1

Build #IU-213.6461.79, built on December 28, 2021

0

I see, thanks for update. Please consider upgrading, the bug is fixed in 2022.1

0

Please sign in to leave a comment.