2

I used the google API to generate a lib.js from a lib.proto. In Typescript I have used it with declare var lib: any;. My problem is that browserify ignores the lib.js because it's only a declaration.

Is there any way to add the lib.js at the right place to the bundle.js?

my tsify command:

browserify -p tsify src/main.ts > bundle.js

my tsconfig:

{
  "compilerOptions": {
    "declaration": false,
    "noImplicitAny": true,
    "target": "ES6",
    "removeComments": true,
    "module": "commonjs",
    "sourceMap": true,
    "rootDir": "src",
    "moduleResolution": "node"
  }
}

my hierarchy:

root
    src
        main.ts
        lib.proto
        lib.js
        lib.d.ts
    bundle.js
    index.html
    package.json
    tsconfig.json

statment:

declare var lib: any;
let p = lib.deserializeBinary(data);

lib.d.ts

FlugRost
  • 45
  • 1
  • 6
  • I'm able to have `.js` files that have associated `.d.ts` files included in the bundle. Without including your configuration details (`tsconfig.json`, tsify options, directory structure, etc.) in the question, answering this is not going to be possible. – cartant Jun 26 '17 at 01:55
  • Thanks for your help! I have updated the question. – FlugRost Jun 26 '17 at 09:43
  • Can you include your `import` statement and the `.d.ts`, too? – cartant Jun 26 '17 at 10:17
  • Updated. I do not have any import statement for this. For my it is only possible to import npm modules. – FlugRost Jun 26 '17 at 16:51

1 Answers1

1

The problem is that you only declare the type of a lib. All module loaders will never bundle lib if you have never imported it.

Just place require('./lib.js');, before you use the lib variable. It should work.

FieryCod
  • 1,674
  • 1
  • 19
  • 27