0

I followed How can I use JointJS with an application built with Angular CLI? to install JointJS on Angular. Anyway I have this problem when I start the project:

Module not found: Error: Can't resolve './node_modules/jointjs/dist/joint.js'

I tried to change this import

const joint = require('./node_modules/jointjs/dist/joint.js'); 

with this: import * as joint from 'jointjs/dist/joint';

In this way I have no problem when I start the project but I cannot use this type of method let m1 = new joint.shapes.devs.Modelbecause I have this error:

TS2339:Property 'devs' does not exist on type 'typeof shapes'

With methods like this: let rect2 = new joint.shapes.basic.Rect or this let link = new joint.dia.Link I have no problems. I think that is an import problem.

This is my angular-cli.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "version": "1.0.0-beta.32.3",
    "name": "jointangular"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/jointjs/css/layout.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/jointjs/dist/joint.js"

      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

my package.json:

{
  "name": "jointangular",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.0",
    "@angular/compiler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "@types/jquery": "^2.0.40",
    "core-js": "^2.4.1",
    "jointjs": "^1.0.3",
    "jquery": "^3.1.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.32.3",
    "@angular/compiler-cli": "^2.4.0",
    "@types/backbone": "^1.3.33",
    "@types/jasmine": "2.5.38",
    "@types/jointjs": "^1.0.3",
    "@types/lodash": "^3.10.1",
    "@types/node": "~6.0.60",
    "backbone": "^1.3.3",
    "codelyzer": "~2.0.0-beta.4",
    "install": "^0.8.9",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lodash": "^3.10.1",
    "npm": "^4.5.0",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.4.2",
    "typescript": "~2.0.0"
  }
}

Do you have any ideas?

Community
  • 1
  • 1
dstyle
  • 68
  • 9
  • did you install the joint js typings? – Astronaut May 02 '17 at 12:56
  • Yes, partially I solved this problem, I installed jointjs writing it in the dependencies of the package.json and then doing npm install (not using directly npm install jointjs)...Now I see the graph but I have this error : `TypeError: Backbone is undefined __webpack_require__ __webpack_require__ webpackJsonpCallback ` – dstyle May 02 '17 at 13:33
  • looks like you need the typings for all the rest of the dependencies then – Astronaut May 02 '17 at 14:11
  • I installed joints, jointjs types, lodash and backbone...I see the example that I wrote but there is this error. Could be an import problem? – dstyle May 02 '17 at 14:18
  • I added new informations about my package.json and angular-cli.json, I don't know if they could be useful – dstyle May 03 '17 at 11:00
  • No idea? I'm trying everything but nothing... – dstyle May 05 '17 at 13:44

1 Answers1

1

I believe that you need to install backbone and lodash into your "dependencies", as joint.js require them.

They are not only needed for development ("dev-dependencies"). This is why it's crashing

Soldeplata Saketos
  • 3,212
  • 1
  • 25
  • 38