Skip to content

I can't import IPinfoWrapper. IPinfoWrapper is undefined #44

Closed

Description

@nuno-cunha-dev

First of all I wanted to say that I just created a new project in nest.js so i am using typescript instead of javascript.

I ran npm install node-ipinfo

And then I created a service that returns the city via IP:

import IPinfoWrapper from 'node-ipinfo';
import { Injectable } from '@nestjs/common';

@Injectable()
export default class IpInfoProvider {
  getCity(): string {
    console.log(IPinfoWrapper);
    const ipinfoWrapper = new IPinfoWrapper('token');
    return 'city-name-test';
  }
}

As you can see, I'm logging the IPinfoWrapper imported class, but I'm getting undefined, this means that when instantiating I get the following error: TypeError: node_ipinfo_1.default is not a constructor

The only way I'm able to instantiate the IPinfoWrapper is to go to the node_modules/node-ipinfo/index.js file and change the return

return m.default;

from: return m.default;
to return m;

Activity

  1. UmanShahzad commented on Sep 10, 2021

    @UmanShahzad
    Contributor

    I've tried reproducing this in a fresh TypeScript project and I can't seem to. https://github.com/ipinfo/node/blob/master/test-app/ipinfo.ts

    But this could have something to do with not properly detecting ES modules, as the index.js you modified above was not being generated by typescript itself, and we may have missed a spot somehow somewhere.

    I've pushed a 3.0.0 version which makes it so we use a typescript-generated index.js file. Can you upgrade and try again?

  2. nuno-cunha-dev commented on Sep 11, 2021

    @nuno-cunha-dev
    Author

    Thank you very much.
    With the new version(3.0.0) everything works fine.

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