1

My first question... "Long time listener, first time caller"

I am migrating a Cesium based webapp from Javascript to Typescript. The webapp is a plugin for a GWT based application and works fine as javascript. We are looking to migrate to TypeScript for a few different reasons. The GWT portion seems to be fine. It is calling the correct methods and opening a client window and initializing the corresponding scripts.

The issue I have run into seems to be a typical one.

I get:

Uncaught TypeError: Failed to resolve module specifier "cesium". Relative references must start with either "/", "./", or "../".

The current directory structure is

Cesium 
  |--> Cesium
  |      |      
  |      |--> Build
  |      |      |--> package.json
  |      |      |--> tsconfig.json
  |      |      |--> Cesium
  |      |      |      |--> Cesium.js
  |      |
  |      |--> Source
  |      |      |--> Cesium.js
  |      |      |--> Cesium.d.ts
  |      |     
  |      |--> (Rest of source folders/files)
  |            
  |-->  ts
  |      |
  |      |--> main.ts
  |      |--> package.json
  |      |--> tsconfig.json
  |
  |-->  app
  |      |
  |      |--> controller.js
  |      |--> app.jsp
  |      |--> main.js (output of tsc)

It has been set up in many ways prior to this configuration. The location of controller.js and app.jsp need to remain the same as this is a small client for a much larger piece of software that would require a lot of refactoring if I changed their locations.

What I have tried:

Prior to creating a "tsconfig" under Cesium/Cesium/Build:

Added the baseUrl and path properties in tsconfig. Changing the moduleResolutions. npm install cesium Calling the cesium.js script from the JSP Changing the import statement to "../Cesium/Source/Cesium.js" Etc. etc.

Currently, I just tried two solutions from the following question involving references:

package-json-is-not-under-rootdir When I run tsc -b, I get no output. When I run tsc, I do get main.js output, but when the JSP brings in the script, I get the aforementioned error.

I have read countless github issues, stack overflow questions, dug around the tsconfig attempting various solutions, to no avail.

The current state of the two tsconfig.json's:

Cesium/Build/tsconfig.json

    {
      "compilerOptions": {
        "composite": true,                                
        "target": "es6",                                  
        "module": "es6",                                
        "rootDir": ".",                                  
        "moduleResolution": "node",                       
        "resolveJsonModule": true,                        
        "outDir": ".",                                   
        "esModuleInterop": true,                             
        "forceConsistentCasingInFileNames": true,            
        "strict": true,                                      
        "skipLibCheck": true                                 
      },
      "files": [
          "package.json"
      ]
    }

ts/tsconfig.json

    {
      "compilerOptions": {
        "target": "es6",                                  
        "module": "es6",                                
        "rootDir": "./",                                  
        "moduleResolution": "node",                       
        "baseUrl": "./",                                  
        "paths": {
             "cesium":["../Cesium/Source/Cesium.js"]
        },                                      
        "resolveJsonModule": true,                        
        "outDir": "../WES/",                                   
        "strict": true,                                      
        "skipLibCheck": true                                 
      },
      "references": [
          { "path" : "../Cesium/Build/" }
      ]
    }

I run tsc from Cesium/ts.

This is my hail mary... If anybody has any insight it would be amazing.

Thank you.

P.S. if I violated the rules here, please let me know how I can do better in my future questions.

0 Answers0