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

SwipeJS is not a module to import #110

Open
paddy-wu opened this issue Jul 3, 2019 · 9 comments
Open

SwipeJS is not a module to import #110

paddy-wu opened this issue Jul 3, 2019 · 9 comments

Comments

@paddy-wu
Copy link

paddy-wu commented Jul 3, 2019

it seems to be forgot to export Swipe,so the es6 or ts module can not import,hope to update the swipe.d.ts file
image

image

@jckw
Copy link

jckw commented Jul 7, 2019

You should just import swipejs, i.e.:

import "swipejs";

(as per this stackoverflow: https://stackoverflow.com/questions/40441252/typescript-typings-give-me-index-d-ts-is-not-a-module).

@powellian
Copy link

The above, using Rollup (es6 imports) didn't work for me.
The following works fine: import Swipe from 'swipejs';

@RandScullard
Copy link
Contributor

In my TypeScript project built with create-react-app, this did not work:

import "swipejs";

It compiled OK but failed at runtime when my code called new Swipe. It appears that Webpack depends on the names you specify in the import to know what types to rename (in this case, Swipe).

The import statement you really want is the one given by @powellian above:

import Swipe from "swipejs";

...however, the TypeScript compiler chokes on this with the error:

File 'node_modules/swipejs/types/swipe.d.ts' is not a module.  TS2306

I was able to fix this by changing this line in swipe.d.ts in my local node_modules folder:

declare class Swipe {

to

export default class Swipe {

As soon as I made this change, everything worked. So I'm with @paddy-wu, the swipe.d.ts file needs to be changed to fix this issue. I'll be happy to do a PR for this if you want.

RandScullard added a commit to RandScullard/swipe that referenced this issue Mar 17, 2020
lyfeyaj added a commit that referenced this issue Mar 30, 2020
@JoseCMRocha
Copy link

JoseCMRocha commented Apr 29, 2020

Hi,
The version 2.2.16 is out with the file "types/swipe.d.ts" on the version 2.2.13, I cleared npm cache deleted node modules but a fresh install of 2.2.16 always brings the types of version 2.2.13.
In #130 this fix should be out on 2.2.16 can anyone confirm the same issue?

Upon checking master types/swipe.d.ts file is not updated with #130 PR

I have gone deep and it seems that on 17th of March the #130 was merged, however on 30th of March @lyfeyaj reverted this changes on the commit dd78865

@RandScullard
Copy link
Contributor

@JoseCMRocha: The change made by @lyfeyaj to types/swipe.d.ts on March 30th did not exactly revert my changes from PR #130. Instead, my change to use "export default" syntax was removed and "export = " syntax was added in its place; note that the file now ends in the line:

export = Swipe;

I'm not sure why @lyfeyaj made this change. But I'm fine with it ether way; it seems like both forms work fine in my application. I'm not seeing any versioning problems as you described.

@mkbctrl
Copy link

mkbctrl commented May 12, 2020

Screenshot 2020-05-12 at 14 30 14

in my case the issue still remains - just installed Swipe to give it a test drive. I have the lastest version.

@lyfeyaj
Copy link
Owner

lyfeyaj commented May 12, 2020

@lyfeyaj
Copy link
Owner

lyfeyaj commented May 12, 2020

@JoseCMRocha 2.2.13 was a typo, is fixed in version 2.2.18

@lyfeyaj
Copy link
Owner

lyfeyaj commented May 12, 2020

@mkbctrl You may need to change your tsconfig.json file as following:

{
    "compilerOptions": {
        "moduleResolution": "node"
    }
}

For further information, please check below
link:
microsoft/TypeScript#8920 (comment)
and
https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md

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

7 participants