# Minimal (getting started) sample using TypeScript

**URL:** <https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886>\
**Category:** CesiumJS\
**Created:** [June 12, 2020, 11:34am UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886 "2020-06-12T11:34:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 12, 2020, 11:34am UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/1 "2020-06-12T11:34:09Z")

</div>

Please provide a minimal code for creating a map using TypeScript, and the required part of the downloaded package for it.

> import \* as Cesium from “cesium”;
> 
> import { Viewer } from “cesium”;
> 
> let map: Viewer = undefined;
> 
> function createTheMap()  
> {  
> if (map === undefined )  
> {
> 
> ```
> map = new Viewer( "mapViewDiv",
> {
> timeline: false,
> animation: false,
> infoBox: false,
> navigationHelpButton: false,
> fullscreenButton: false,
> geocoder: false,
> shadows: false  
> } );
> 
> console.log( map );
> 
> addMarker();
>    
> 
> }
> 
> map.zoomTo(map.entities);
> 
> ```
> 
> };

this is the function which I am trying to create the map as I would do normally in JS, but it report me the following error :  
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]  
Unhandled exception rendering component: cesium\_1 is undefined  
when running.

---

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 12, 2020, 1:18pm UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/2 "2020-06-12T13:18:13Z")

</div>

Found the issue.  
Seems like referenting directly Viewer is not a good idea and it is leading to the issue above in ASP.

---

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 13, 2020, 1:38pm UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/3 "2020-06-13T13:38:38Z")

</div>

Unfortunately this mistake:

> Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]  
> Unhandled exception rendering component: cesium\_1 is undefined

is gone, but now I am not sure what is wrong with the namespace or something, since I am receiving the follow :

> TypeError: Error resolving module specifier: cesium

in Firefox, and :

> Uncaught TypeError: Failed to resolve module specifier “cesium”. Relative references must start with either “/”, “./”, or “…/”.

in Chrome.

What could be causing this issue ?

---

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 14, 2020, 1:22pm UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/5 "2020-06-14T13:22:23Z")

</div>

> [@Yordan\_Yanakiev1](#):
>
> Pasted in StackOverflow as well, but there is silent as well. 😑

> <https://stackoverflow.com/questions/62372004/using-cesium-with-typescript>

---

<div class="post-metadata">

**Author:** ![James\_B](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/james_b/32/2424_2.png) [@James\_B](https://community.cesium.com/u/James_B)\
**Post date:** [June 16, 2020, 8:16am UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/6 "2020-06-16T08:16:20Z")

</div>

Cesium is distributed as a Node package (NPM). The way Typescript supports typings in packages is to put a “types” field in the `package.json` which points to the typings file (`.d.ts`) for the package. This way, when you say `import { Viewer } from cesium` in your TS, the IDE knows to look at `node_modules/cesium/package.json` which points to `node_modules/cesium/Source/Cesium.d.ts`. You may have to explicitly tell TS to use “node style” module resolution, which is a line in your `tsconfig.json`.

That said, your error output sounds highly ASP.NET-specific to me. I’m not familiar with it, so I can’t really help you with that. Have you consumed other libraries that distribute their own typings using the `types` field in `package.json`? I did a grep through my installed modules and found [this one](https://www.npmjs.com/package/fast-deep-equal) at random – if you `npm install` that, then paste some of their sample code into your editor, you should get Intellisense without any additional steps as long as your project config is correct. If that random package works and Cesium doesn’t, please reply here, but I suspect it won’t, which means it’s to do with your `tsconfig` or your [ASP.NET](http://ASP.NET) settings.

---

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 16, 2020, 10:38am UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/7 "2020-06-16T10:38:34Z")

</div>

but since the project run without server - entirely on the client - would this be issue that i am integrating node.js?  
as well up to now i lacked of tsconfig.json. what should i put on it ?

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [June 22, 2020, 8:51pm UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/8 "2020-06-22T20:51:48Z")

</div>

Even if the project ultimately will run on the client without a server, you still need a built step, since TypeScript is not supported in the browser. This is typically what you’d have a NodeJS script for (and then to run a static HTTP server to host the generated files so you can run them in your browser).

---

<div class="post-metadata">

**Author:** ![James\_B](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/james_b/32/2424_2.png) [@James\_B](https://community.cesium.com/u/James_B)\
**Post date:** [June 23, 2020, 9:04am UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/9 "2020-06-23T09:04:40Z")

</div>

I want to emphasize that I have no experience setting up [ASP.NET](http://ASP.NET) with TypeScript or NPM, but I did find [this page in the Typescript handbook](https://www.typescriptlang.org/docs/handbook/asp-net-core.html) that talks about getting started. They use Gulp as a build step. If you’re still lost, maybe follow that guide to get a “Hello world” project working, then add a simple NPM module like the one I linked above (`fast-deep-equal`) and get their sample code working. After that, install Cesium in your project and see if you can get a basic Viewer constructed.

If that doesn’t help, you’re probably better off asking on StackOverflow – again, this is not a Cesium problem, but an [ASP.NET](http://ASP.NET) + Typescript problem.

---

<div class="post-metadata">

**Author:** ![Yordan\_Yanakiev1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yordan_yanakiev1/32/2128_2.png) [@Yordan\_Yanakiev1](https://community.cesium.com/u/Yordan_Yanakiev1)\
**Post date:** [June 26, 2020, 10:06pm UTC](https://community.cesium.com/t/minimal-getting-started-sample-using-typescript/9886/10 "2020-06-26T22:06:35Z")

</div>

Well… finally I’ve given up on TypeScript (at least for now) and I have switched to JS.  
Probably will wait for someone to showcase implementation of Blazor + TypeScript, and then I will report back. :’(
