0

First and foremost, it may be worth mentioning that I am writing an Electron application and would like to use typescript for a number of reasons. Unfortunately, I am running into some issues and have been spinning my wheels on this for several hours at this point, so I would greatly appreciate any insight as I'm very new to typescript.

tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "sourceMap": true,
        "moduleResolution": "node"
    },
    "compileOnSave": true
}

renderer.ts

import Case from "../typescript/case";

This results in the following for the above line:

Uncaught SyntaxError: Unexpected identifier

case.ts

import Client from "./client";

export default class Case {
    CaseNumber: number;
    Client: Client;
    DateOfInjury: Date;
    LastUpdated: Date;
    LastUpdatedBy: string;

    constructor() {
        this.CaseNumber = 0;
        this.Client = new Client();
        this.DateOfInjury = new Date();
        this.LastUpdated = new Date();
        this.LastUpdatedBy = "";
    }
}

I have tried a number of variations of the above to get past this error but have been unsuccessful in finding a solution. Perhaps someone with more experience in this space can provide some guidance?

Adam Chubbuck
  • 1,612
  • 10
  • 27
  • If there is any additional information that I can provide to make this clearer, please let me know. – Adam Chubbuck Nov 01 '19 at 16:18
  • The `Unexpected identifier` should have the location of the error. Usually in the line above the error in your terminal. Can you include it in your question ? – Seblor Nov 01 '19 at 16:21
  • @Seblor Apologies. I did include this information but the order of the code is misleading. The error is displayed when the import statement in renderer.ts is executed. – Adam Chubbuck Nov 01 '19 at 16:23
  • Shouldn't it be `import { Case } from "../typescript/case";`? – ug_ Nov 01 '19 at 16:27
  • @ug_ Using that, I receive the following error: Module '""' has no exported member 'Case'. – Adam Chubbuck Nov 01 '19 at 16:30
  • A cup of coffee to anyone who can help figure this out. =] – Adam Chubbuck Nov 01 '19 at 17:07
  • does adding `"module": "commonjs"` to your tsconfig fix this? – pushkin Nov 01 '19 at 19:46
  • Does this answer your question? [How can I use an es6 import in node?](https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node) – pushkin Nov 01 '19 at 19:47
  • @pushkin Unfortunately, that results in the following: renderer.ts:1 Uncaught ReferenceError: exports is not defined – Adam Chubbuck Nov 01 '19 at 20:58
  • @pushkin I appreciate the link but I will need to package this and in doing so, options for node will not persist. – Adam Chubbuck Nov 01 '19 at 21:11
  • is it an option to change how you do your exports, so you use commonjs' exports – pushkin Nov 01 '19 at 21:15
  • @pushkin I'm open to changing any of the code around so if you have an example that you know works and is similar to the above, please let me know. – Adam Chubbuck Nov 01 '19 at 21:21

0 Answers0