TypeStrong / tsify

Browserify plugin for compiling TypeScript
344 stars 75 forks source link

Cannot find module with @types import #248

Open tqwewe opened 5 years ago

tqwewe commented 5 years ago

I am unable to import a module from a TypeScript @types package. In my main file I have:

import { BdApi } from 'bandagedbd__bdapi'
console.log(BdApi)

This compiles correctly when I run tsc but not with node build.js.

My tsconfig looks like this:

"compilerOptions": {
    "target": "es6",
    "module": "es6",
    "moduleResolution": "node"
}

And my build.js file:

const browserify = require('browserify');
const tsify = require('tsify');
const babelify = require('babelify');

browserify()
    .add('src/main.ts')
    .plugin(tsify)
    .transform(babelify, { extensions: ['.ts', '.tsx'] })
    .bundle()
    .on('error', function (error) { console.error(error.toString()); })
    .pipe(process.stdout);

And my .babelrc

{
    "presets": ["@babel/preset-env"]
}

And the output when running node build.js

Error: Cannot find module 'bandagedbd__bdapi' from 'C:\Users\...\src'

I can import * as React from 'react' from @types/react, but not import { BdApi } from 'bandagedbd__bdapi'.

cartant commented 5 years ago

This is not a tsify problem. That package has no available @types:

$ npm dist-tag ls @types/bandaged__bdapi
npm ERR! dist-tag ls Couldn't get dist-tag data for @types/bandaged__bdapi
npm ERR! code E404
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/-/package/@types%2fbandaged__bdapi/dist-tags

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Nicholas\AppData\Roaming\npm-cache\_logs\2019-01-10T12_12_53_795Z-debug.log
tqwewe commented 5 years ago

@cartant Sorry, that's a handwritten typo - It should be bandagedbd__bdapi. In my TypeScript file it is correct, just in that code snippet I did a typo.

If you could re-open the issue for time being; would be much appreciated.

cartant commented 5 years ago

You should first verify that the import works with a plain vanilla .ts file that's compiled using tsc.

I.e. make sure that this compiles using tsc:

import { BdApi } from 'bandagedbd__bdapi'
console.log(BdApi)
tqwewe commented 5 years ago

Imgur

yep, unfortunately still doesn't work.


tsc produces the main.js file whilst node build2.js does not.

cartant commented 5 years ago

I'm not going to have time to look into this anytime soon. You can, however, use the logging built into tsify to see if you can figure out why that particular package is problematic. See https://github.com/TypeStrong/tsify/blob/master/CONTRIBUTING.md#debugging

tqwewe commented 5 years ago

TSIFY 3228: + 0 file(s) found in node_module This is a line I found from the log.