Skip to content

Cannot find module with @types import #248

Open

Description

@tqwewe

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'.

Activity

  1. cartant commented on Jan 10, 2019

    @cartant
    Contributor

    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
    
  2. tqwewe commented on Jan 10, 2019

    @tqwewe
    Author

    @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.

  3. cartant commented on Jan 10, 2019

    @cartant
    Contributor

    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)
  4. tqwewe commented on Jan 10, 2019

    @tqwewe
    Author

    Imgur

    yep, unfortunately still doesn't work.


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

  5. cartant commented on Jan 10, 2019

    @cartant
    Contributor

    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

  6. tqwewe commented on Jan 10, 2019

    @tqwewe
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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