'vs code node version is older than node version on my system
I was programming with typescript, then this happened when i runned "tsc fileName.ts"
"Accessors are only available when targeting ECMAScript 5 and higher."
So i searched for solutions and "tsc -t es5 fileName.ts" works.
But i'd like it was by default, so i searched more and a lot of answers talk about modifying tsconfig.json file.
when i search on my system (windows 8.1) for tsconfig.json file, i get 2 files with this name.
one in: C:\Users\Peppe.p2\pool\plugins\org.eclipse.wildwebdeveloper_0.5.10.202008281220\node_modules\vscode-emmet-helper
content:
{
"compilerOptions": {
"target": "es6",
"lib": ["es2016"],
"module": "commonjs",
"outDir": "out",
"sourceMap": true,
"allowJs": true
},
"exclude": ["node_modules", "out"]
}
and the other one in: C:\Users\Peppe.p2\pool\plugins\org.eclipse.wildwebdeveloper_0.5.10.202008281220\node_modules\uri-js
content
{
"compilerOptions": {
"module": "es2015",
"target": "esnext",
"noImplicitAny": true,
"sourceMap": true,
"alwaysStrict": true,
"declaration": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"outDir": "dist/esnext",
"strictNullChecks": true
},
"include": [
"src/**/*"
]
}
last thing. if i run "node -v" i get: 14.15.1
if i open my vs code editor, and i click on "Help" and then "About" it says:
..
..
Node.js 12.14.1
..
..
its normal to have differenet versions of node? maybe i have local and global? how do i set es 2016 (or better es 2017) by default?
Solution 1:[1]
The title of this question and the question you are asking are unrelated. The version of node you have on your system has nothing to do with the TypeScript Compiler (tsc). The error you are seeing is because the default target for tsc is ES3 so setting the target (-t flag) to ES5 fixes the problem. If you are developing in TypeScript you usually have a tsconfig file local to the project you are working on with all the settings necessary for that project. If you don't the the TypeScript compiler is going to use the defaults.
You cannot have the tsc target be ES5 globally by default. You need to create a tsconfig file in your project and when you call tsc tell it which tsconfig file to use
Solution 2:[2]
In my case I had 2 versions of node installed on the OS and my VS Code was using a different (older) version than the OS. I solved it as follow:
- Run in your OS's terminal
node -v
. (Also you can checknvm which current
)
- Check in your VS Code terminal that versions are differents by running
node -v
and alsonvm which current
. In case they are differents continue the following steps.
- Go to the VS Code terminal and run
nvm use <your-OS-version>
Restart your Visual Studio Code so it take the changes
Done. You can check that this take effect by running
node -v
andnvm which current
again and see the issue is solved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrew Alderson |
Solution 2 | Adriana Hernández |