GoJS 1.6.13 and Electron

I am using GoJS 1.6.13 and I see your example with Electron.

go = require(“gojs”); // assumes: $ npm install gojs

My IDE is VS code, which has a really strong support on intellisense. It complains that gojs is not a module. I then go to go.d.ts to see the definition, the module is defined as “go” instead of “gojs”. When I change this line to go = require(“go”), my compiler is happy but I cannot launch it through Electron. But if I just double-click on html, it still works.

Uncaught ReferenceError: go is not defined

Do you have any idea? This is currently blocking my work.

Thanks,
Chuan

In version 1.6.3, we had not yet renamed the TypeScript definition file to be “go.d.ts”. If you have recently done an “npm install gojs” or “npm update”, you would not be using version 1.6.3 any more.

We’ll look into using Electron again.

Try this:

import * as go from "gojs";

You might need to copy go.d.ts to gojs.d.ts.

I must agree with you that using modules in the different JavaScript environments is very confusing.

Thanks Walter.

I believe I am on the latest version now. However, even after I rename go.d.ts to gojs.d.ts, I still running into some issue.

If I add import line, I can run it without any error but I will lose all intellisense. What makes this inconsistent?

-Chuan

I think I “hacked” it out. What is the wrong on using ‘go’ as filename, namespace and module name? Using ‘gojs’ resolves all issues.

I have to do three things in order to make typings/intellisense and runtime work at the same time.

  1. rename go.d.ts to gojs.d.ts

  2. modify the namespace ‘go’ in gojs.d.ts to ‘gojs’ and update the last line of export module to gojs

declare module “gojs” { // comment out module declaration for TypeScript 2.0
export = gojs; // but keep export = go in all versions for compatibility with AMD and CommonJS
}

  1. do this in my typescript code

///
import * as go from ‘gojs’

Thanks for sharing your results. We’re not experts in typescript, so we’ll review this when updating our definition file.

I struggled all day trying to get gojs intellisense working in VS code. (It had previously been working, and intellisense for other modules was working).

This process appeared to work:

  1. Delete the directory C:\Users[yourname]\AppData\Roaming\npm-cache\gojs
  2. Delete the directory C:\Users[yourname][Your project path]\node_modules\gojs
  3. Delete the gojs entry in the package.json file.
  4. Run npm install gojs --save
    4.1. This results in the latest version of gojs being installed.
    4.2. The –save results in the package.json file being updated.

I’m not sure all the steps were needed, and I had to start/restart VS code a couple of times. Still the “secret” is buried somewhere in the steps above.