1

First off: I am completely new to Node.js, so please bear over with me if this is a dumb question.

I am trying to get browserify and tsify to work with TypeScript and the SVG.js library. As far as I understand, I should be able to

  1. Write TypeScript code that uses the SVG.js library
  2. Compile this code to vanilla JS and bundle it together with the library itself for use in the browser using browserify and tsify

Step 1 is easy, but Step 2 is causing me problems. Even if I write the simplest of TypeScript programs containing only the line import * as SVGJS from 'svg.js', and then run the command specified in the tsify docs (browserify main.ts -p [ tsify --noImplicitAny ] > bundle.js), the compiled bundle.js file has the following contents:

enter image description here Here, I was expecting to see the the code for the entire SVG.js library. At least that's what I get if I create a vanilla JS file containing var SVGJS = require('svg.js') and run browserify on that.

Can anybody tell me what I am doing wrong? I have installed all the required node modules, and am getting no warnings or errors during compilation. Please let me know if I need to provide more information.

wstr
  • 910
  • 2
  • 13
  • 23
  • Does Browserify do Treeshaking? If so, it wont include the svg lib in the bundle if you dont use it – Fuzzyma Apr 01 '19 at 09:14
  • @Fuzzyma I don't think so. If I extend my program with a few lines of code that use the imported SVG.js library, I get the same result in my bundle.js file (except with the extra lines now appended). – wstr Apr 01 '19 at 11:26
  • Hm, I never used browserify and therefore cant help more with that. However, you could try using the new version 3.0.12 which is written with esm in mind. Maybe that helps – Fuzzyma Apr 01 '19 at 11:30
  • @Fuzzyma Thanks a lot for your help so far! I've updated to 3.0.12, but now the TypeScript compiler gives me the following error: `node_modules/@svgdotjs/svg.js/svg.js.d.ts:296:18 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.` If I run the command `tsc main.ts --lib es2015`, I get a boatload of new errors (118 to be exact). – wstr Apr 01 '19 at 12:12
  • I know that it works because I tested that bit. It's all about the libs which you need to include. Unfortunately I don't know anymore. You need to drive es6 and you need a Dom. Somewhere in the docs is written which libs are available – Fuzzyma Apr 01 '19 at 13:04

0 Answers0