swipe icon indicating copy to clipboard operation
swipe copied to clipboard

SwipeJS is not a module to import

Open paddy-wu opened this issue 5 years ago • 9 comments

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

paddy-wu avatar Jul 03 '19 08:07 paddy-wu

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).

jckw avatar Jul 07 '19 18:07 jckw

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

powellian avatar Aug 30 '19 12:08 powellian

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 avatar Jan 24 '20 18:01 RandScullard

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 dd788653b62eb525e1312e17c715982c4f34e646

JoseCMRocha avatar Apr 29 '20 12:04 JoseCMRocha

@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.

RandScullard avatar Apr 29 '20 15:04 RandScullard

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.

mkbctrl avatar May 12 '20 12:05 mkbctrl

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

lyfeyaj avatar May 12 '20 18:05 lyfeyaj

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

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

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

lyfeyaj avatar May 12 '20 18:05 lyfeyaj