Node 23 support for Typescript and Webstorm
With index.mts:
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const json = await response.json();
console.log(JSON.stringify(json, null, 2));
and package.json:
{
"name": "typescript",
"version": "1.0.0",
"description": "",
"main": "index.mts",
"tyep": "module",
"scripts": {
"start": "node index.mts"
},
"private": true
}
Node version:
> node --version
v23.6.1
Webstrom shows squigglies under the await
with error:
TS1378: Top-level await expressions are only allowed when the module option is set to es2022, esnext, system, node16, nodenext, or preserve, and the target option is set to es2017 or higher.
But the code runs just fine:
> node index.mts 25-01-26 10:24PM
(node:4642) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
Is this a bug or do I need to do some additional config?
请先登录再写评论。
Do you have the
tsconfig.json
in your project? What is a result of runningtsc
in your app root?Hi Elena,
The whole point of new direct Typescript support in Node is that you do not need to use
tsconfig.json
explicitly.But yes, after adding this
tsconfig.json
I do not see the error:The Typescript compiler still uses the
commonjs
“module”
andES5
“target”
by default, regardless of the Node.js interpreter being used. You will see the same errors when running `tsc
` in terminal unless the options are specified explicitly either in the tsconfig.json or in the command line.