Skip to content

Cannot find ambient module declaration in .d.ts #256

@mnovotny

Description

@mnovotny

When trying to transpile and bundle .ts file via Gulp/Browserify/Tsify the task fails with "Cannot find module" although standard tsc transpilation works.

I created an ambient module declaration based on TypeScript handbook:

// File: ./src/node_modules/mymodule.d.ts
declare module "mymodule"
{
    export class MyModule
    {
        public static Report(message:string):any;
    }
}

And I'm trying to import it in another file:

// File: ./src/consumer.ts
import {MyModule} from "mymodule";
MyModule.Report("MyModule was found by consumer");

The standard transpilation by TSC works ok: tsc ./src/consumer.ts

But when trying to transpile with the use of Browserify/Tsify/Gulp the gulp task fails:

// File: gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var tsify = require('tsify');

gulp.task('default', function () {
    return browserify({
        basedir: '.',
        debug: true,
        entries: ['src/consumer.ts'],
        cache: {},
        packageCache: {}
    })
    .plugin(tsify)
    .bundle()
    .pipe(source('consumer.js'))
    .pipe(gulp.dest('dist'));
});

The error is: Error: Cannot find module 'mymodule' from 'D:\Projects\Playground\TSTest\src'

I've put together a minimal repository which replicates the issue:
https://github.com/mnovotny/tsify-issue-250

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions