Visual Studio Code not performing error checking in Javascript - javascript

I've tried following these instructions:
https://code.visualstudio.com/Docs/runtimes/nodejs
I am not getting the green/red swiggly lines at all. Is there something I'm missing?
You can also see the same thing in this video:
https://youtu.be/sE8_bTEBlFg?t=1m37s
As far as I know, they're running the default editor. I've tried installing typings and typescript using npm. I've Followed that tutorial to get Javascript intellisense for node.js, but I fail to get either error/warning checking or any type information for node.js modules.
Is there a location the type files should be installed to in order to make them global to every JS project you create in VS Code?

OK, so I managed get get some code suggestions working after reading up online. Without using the whole Typings tools, I acquired node.d.ts (found it on my computer inside C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions) and placed that in my project's directory structure inside the ".vscode" folder. At the top of my .js file I added the following line:
/// <reference path=".vscode/node.d.ts" />
The code seems to be recognized now.
I read up on this tip here: How to Import Intellisense files into vsCode (Visual Studio Code)

If you are using ESLint and you have an .eslint.js file in the project root you also need the eslint dependency installed in the project. Otherwise, if there is a .eslint.js file but the ESLint dependency is not installed Visual Studio Code will report nothing in the editor.

Maybe you didn't use the -g flag to install them globally? Alternately, perhaps it's a missing jsconfig.json file?

Related

VSCode associate JavaScript files as Typescript incorrectly, how to fix it

In Visual Studio Code, I keep getting errors on my JavaScript files from 'ts' attached. tsError on js files
Currently, I have two solutions:
Putting // #ts-nocheck at the top of each .js file
Putting "javascript.validate.enable": false in my user settings.json in VSC.
I don't like any of them, because the underlying problem is VSC associate my js files incorrectly as TypeScript files. How to tell VSC to change this behavior? Thanks!
I uninstalled the typescript packages that I installed before as well by running
npm uninstall -g ts-node typescript. It did not help.

Cannot use import statement outside a module error after export ZIP from CodeSandbox

I've downloaded this Phaser/MatterJS example from Codesandbox (->File ->Export to ZIP).
Running it locally returns this error:
Uncaught SyntaxError: Cannot use import statement outside a module - index.js:1
How to fix this?
What I tried so far:
I've installed all dependencies
Updated to latest NodeJS
Running it with a local server
Just as you have seen yourself the javascript that is written in the files is not something that the browsers understand out of the box, and so errors were thrown your way.
To send js that browsers understand, you need to use a tool like webpack, parcel. already in the project you shared parcel is used.
You have to do the following:
install the dependecies of the probject
in the root dir of the project run npm run start
parcel will bundle the files and then open an html page with the results
unfortunately when i tried this parcel did not work for me, there were errors related to JSON loading, however i have managed to get the game to work, by running npm run build, this will output for you the build files in a folder called dist.
Go to the dist folder, and start a local server there and visit the file it should work, however again for me it did not work. but i noticed that its due to parcel not getting the correct relative path of the bundled js file.
To solve that, open the index.html file in the dist folder, you will find that there is one script there
<script src="/js.d8530414.js"></script>
I had to change that to
<script src="./js.d8530414.js"></script> // because this was the correct file in my file system
After that visit the html file in the dist folder, and the game works fine.
Obviously this way of working is not conveninent, since for each change you want to see you have to build the project again using npm run build. You need to solve the problem of npm run start not working, it could be that this problem never occurs to you if you are on different os than mine. If it happens then i suggest updating parcel and trying again, if problem still persists, then you can look here since issue seems related to phaser wanting the json file as json, while parcel compiling it to javascript object.
index.html:
<script type = "module" src = "./js/index.js">
You have to tell the browser that this js file is a module, then it will change some things on the backside for you to use this. This article is very helpful for getting started with modules.

Developing TypeScript without an installed IDE or editor

I work in a place that restricts me from downloading and installing any applications, regardless of job roles. I have several web apps that I want to migrate to Angular 2 with TypeScript. I'm a C# developer in my own time and TypeScript is very appealing as it's statically typed and just compiles down to JavaScript.
How can I develop with TypeScript without having access to an installed IDE or code editor? Are there any online environments that allow the use of TypeScript definition files that provide code help/intellisense?
How can I develop with TypeScript without having access to an installed IDE or code editor
I am hoping you can do npm install typescript. If you can just run npm install typescript -g and then run typescript as tsc -w -p tsconfig.json in your code directory. This will allow you to run the compiler in the background leaving you free to use even notepad if you have to.
Alternatively you can just download the zip file from : https://github.com/Microsoft/TypeScript/releases and if you have node you can run node ./bin/tsc etc from the extracted directory.
Use Codenvy:
It needs some manual tweaks but somebody figured them out already: https://groups.google.com/a/codenvy.com/forum/#!topic/codenvy/R4myXA9MygA
You can try the playground: http://www.typescriptlang.org/Playground
Although it doesn't allow references to other files.

How to use jsdoc in my script running on node.js?

I would like to use jsdoc module to extract documentation entries from some source code.
I have installed jsdoc module and I can use jsdoc in the command line.
But when I require("jsdoc") in my code, nodejs throws an error saying Cannot find module 'jsdoc'.
I have nodejs v0.8.25 and JSDoc 3.3.0-alpha2. It is installed both locally and globally.
I can use jsdoc command and I have jsdoc in my node_modules folder.
I cannot see where the problem is.
Where can I find some documentation about jsdoc other than how to use it in the command line interface or how to document js source code. I would like some API documentation.
I was looking to use jsdoc as a library too, and I stumbled on the same issue as you did.
You have done nothing wrong, it was just never intended to be used as a library.
There is an issue on the jsdoc's github project page relating to this. Hegemonic, the main contributor of JSDoc said:
JSDoc isn't really designed to be used as a library
You might want to express your desire to for creating an API for nodejs on the issue linked above.
The require('jsdoc') fails because there is no main field declared in the jsdoc's package.json. It might default to 'index.js' or 'main.js', but there is no such file either.
It sounds like you haven't installed jsdoc correctly. Run npm install -g jsdoc from your command line. If you run this inside a new terminal window that's in the default directory you shouldn't have any problems. I've had issues where I've tried to install a node module globally from my current working directory and for whatever reason the module doesn't install globally.
If it is about an automatic documentation tool in general, you could also use YUIDoc.
Following these three steps, you will have your automatic documentation:
Installing it: npm -g install yuidocjs
Format your comments regarding the YUIDoc Syntax Reference
In your console run yuidoc . on top of your JS source tree

Running TypeScript project in the browser

I found out about TypeScript, and installed the Visual Studio 2012 Plugin, downloaded the source code and ran the first sample after referencing the .ts file in my HTML document:
function Greeter(person) {
return "Hello, " + person + ".";
}
var user = "James Kent";
document.body.innerHTML = Greeter(user);
And then proceeded to compile the code at the command-line, with:
tsc greeter.ts
But I could not compile it, as Visual Studio says:
Command "tsc" is not valid.
After looking all over the TypeScript website, I was unable to find any information about how to get it working. A Google search also yielded no relevant results.
How can I get TypeScript working?
Update: Running any of the samples provided with the source code simply displays a blank page in any browser. However, samples appear to work just fine on the TypeScript website.
Your system cannot find the path to the compiler. The compiler executable is here (on my x64 Win 8 system) if you want to register it yourself.
C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0\
Use it to compile the .ts file to a .js, and use that in your html instead of trying to compile it directly in the browser. That would be really slow.
You can look at the "HTML Application with TypeScript" project in VS, it is configured to compile your TypeScript at the project build.
A simple way to get tsc working on the command line is using nodejs and the corresponding package manager npm. You can get them from nodejs.org. Once you have set up nodejs, all you have to do is install the compiler with
npm install -g typescript
Executing Typescript directly in the browser is rather complicated. Typescript compiles to Javascript, so what you want is reference the compiled code in your html.

Categories