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 from ./node_modules #8807

Closed
c9s opened this issue May 25, 2016 · 5 comments
Closed

Cannot find module from ./node_modules #8807

c9s opened this issue May 25, 2016 · 5 comments

Comments

@c9s
Copy link

c9s commented May 25, 2016

Don't know if this is a expected bahaviour ? I thought loading node modules should be OK?

TypeScript Version:

1.8.0, 1.8.0-beta, also in 1.9.0-dev.20160217

Install

 npm install object-assign

so we will have node_modules/object-assign/index.js installed.

Config

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowJs": true
  },
  "files": ["entry.ts"]
}

Code

import * as assign from "object-assign";

Expected behavior:

should load the module from node_modules/object-assign

Actual behavior:

error TS2307: Cannot find module 'object-assign'.
@c9s
Copy link
Author

c9s commented May 25, 2016

typings install object-assign

And change import statement to

import assign from "object-assign";

solves this problem.

@c9s c9s closed this as completed May 25, 2016
@c9s c9s reopened this May 26, 2016
@c9s c9s closed this as completed May 26, 2016
@tutok
Copy link

tutok commented Aug 26, 2016

Is there any way to ignore error TS2307 in case where typings were not available for package installed from npm?

@RyanCavanaugh
Copy link
Member

declare module "the-module-name";

Which package is missing type definitions? I'm working on a tool to generate these quasi-automatically and am interested to try it out

@tutok
Copy link

tutok commented Aug 26, 2016

Thanks for quick response!

Should I declare it in typings\globals\[the-module-name].d.ts ?
For sure, your one line solution produce error TS1005: '{' expected.. I assume that your answer is an shortcut for writing whole typings for this module, am I right?

I am searching for quick solution for situation where I can not find typings, writing them from scratch is not what I expect.

I can not find typings for react-simple-dropdown and react-cookie.

@RyanCavanaugh
Copy link
Member

Sorry, that syntax is specific to TS2.0.

It doesn't matter where you place the file as long as it's part of your compilation.

In pre-2.0 you can write the equivalent

declare module "react-cookie" { 
  var x: any;
  export = x;
}

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants