3

I have an ES6 JavaScript class named DB defined as follows:

// db.js
"use strict";

export default class DB {
  ...
}

And a TypeScript file that looks like the following:

// surgeons.ts
"use strict";

import DB from "./db";

I expect this to just work but I get the following error:

Browserify Error { [TypeScript error: app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module './db'.]
  message: 'app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module \'./db\'.',
  fileName: 'app/source/common/surgeons.ts',
  line: 3,
  column: 16,
  name: 'TypeScript error' }

I tried to define a db.d.ts file as described here but this generated the error:

Browserify Error { [TypeScript error: app/source/common/surgeons.ts(5,16): Error TS2306: File 'app/source/common/db.d.ts' is not a module.]
  message: 'app/source/common/surgeons.ts(5,16): Error TS2306: File \'app/source/common/db.d.ts\' is not a module.',
  fileName: 'app/source/common/surgeons.ts',
  line: 5,
  column: 16,
  name: 'TypeScript error' }

My tsconfig is as follows:

{
  "compilerOptions": {
    "module": "es6",
    "target": "es6",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true
  },
  "include": [
    "app/source/**/*",
    "test/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}
3
  • 1
    Does this work with "allowJs": true in your "compilerOptions"? Commented Jun 29, 2017 at 16:44
  • 2
    Do not forget to specify the version of Browserify and your building scripts. Commented Jun 29, 2017 at 16:45
  • Daniel Rosenwasser: Thanks, that fixed my issue! Commented Jun 29, 2017 at 17:39

1 Answer 1

5

Per Daniel Rosenwasser, setting "allowJs": true in the tsconfig.json "compilerOptions" section did the trick. I didn't have to use a .d.ts file at all.

Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't this be "allowJs": true ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.