Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Unable to import node_modules #19

Closed
johnman opened this issue May 28, 2015 · 1 comment
Closed

Unable to import node_modules #19

johnman opened this issue May 28, 2015 · 1 comment

Comments

@johnman
Copy link

johnman commented May 28, 2015

Hi,

I've given your plugin a try and managed to use the new es6 import syntax to import other source files and use webpack to bundle it. This loads without issue and has nice sourcemap support.

The problem came up when I tried to bring in a new module. A simple example would be uuid.

So the steps are as follows:

  • npm install uuid
  • fetch the d.ts file from definitely typed and a reference to it to my index.ts file (as an example) typescript then determines that you can import this e.g. import * as uuid from 'uuid';
  • call the imported file and log to the console (basic example).

It should be really simple but just doesn't work. It complains that it cannot find the module. I've tried adding moduleDirectories to the resolve part of the config and specifying the full path to the node_modules folder and even tried defining resolveLoader with modulesDirectories (because another complaint is it can't resolve source-map-loader.

Is it possible to add an extra example that has a packages.json that brings in uuid and then references it using the new es6 syntax (i also tried require)?

Thanks!

@s-panferov
Copy link
Owner

@johnman I understand what's wrong. The problem is that the module you install with npm i uuid doesn't have a proper .d.ts file on DefinitelyTyped. The closest analog on DefinitelyTyped is node-uuid and you can use it, but you need to do one of those things:

  1. Alias node-uuid to uuid to your webpack.config.js
  2. Or add these lines to one of your project's .d.ts files:
declare module "uuid" {
    var uuid: UUID;
    export = uuid;
}

The loader can't do anything with this issue, sorry.

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

2 participants