Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module with @types import #248

Open
tqwewe opened this issue Jan 10, 2019 · 6 comments
Open

Cannot find module with @types import #248

tqwewe opened this issue Jan 10, 2019 · 6 comments

Comments

@tqwewe
Copy link

tqwewe commented Jan 10, 2019

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
Copy link
Contributor

cartant commented Jan 10, 2019

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

@cartant cartant closed this as completed Jan 10, 2019
@tqwewe
Copy link
Author

tqwewe commented Jan 10, 2019

@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
Copy link
Contributor

cartant commented Jan 10, 2019

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
Copy link
Author

tqwewe commented Jan 10, 2019

Imgur

yep, unfortunately still doesn't work.


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

@cartant cartant reopened this Jan 10, 2019
@cartant
Copy link
Contributor

cartant commented Jan 10, 2019

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
Copy link
Author

tqwewe commented Jan 10, 2019

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants