waitingsong / node-win32-api

win32 api
MIT License
430 stars 55 forks source link

Cannot find module 'win32-def/struct.def' #40

Closed zgpio closed 2 years ago

zgpio commented 2 years ago

Change "types": "src/index.ts" to "types": "./dist/index.d.ts" in win32-api/package.json, the error below disappear, but why.

$ npm run build && chcp 65001 && electron ./dist/main.js
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> electron-quick-start-typescript@1.0.0 build
> tsc

node_modules/win32-api/src/index.ts:25:26 - error TS2307: Cannot find module 'win32-def/struct.def' or its corresponding type declarations.

25 export * as DStruct from 'win32-def/struct.def'
                            ~~~~~~~~~~~~~~~~~~~~~~
node_modules/win32-api/src/index.ts:27:25 - error TS2307: Cannot find module 'win32-def/common.def' or its corresponding type declarations.
waitingsong commented 2 years ago

maybe lack of types in win32-def/packages.json. pls try latest version v19.8.3. if still error, i'll change it point to dist/...

zgpio commented 2 years ago

I tried latest version v19.8.3,still have the same error. And, if I don't remove "types": "src/index.ts" in win32-def/package.json, the v19.8.3 also adds the following error:

node_modules/win32-def/src/lib/helper.ts:4:21 - error TS7016: Could not find a declaration file for module 'ref-union-di'. 'C:/Users/zhaoguopan/electron-quick-start-typescrip
t/node_modules/ref-union-di/lib/union.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ref-union-di` if it exists or add a new declaration (.d.ts) file containing `declare module 'ref-union-di';`

4 import UnionDi from 'ref-union-di'
                      ~~~~~~~~~~~~~~

node_modules/win32-def/src/lib/helper.ts:15:3 - error TS2578: Unused '@ts-expect-error' directive.

15   // @ts-expect-error
     ~~~~~~~~~~~~~~~~~~~

node_modules/win32-def/src/lib/helper.ts:19:3 - error TS2578: Unused '@ts-expect-error' directive.

19   // @ts-expect-error
     ~~~~~~~~~~~~~~~~~~~
waitingsong commented 2 years ago

Give me a sample repo to test ?

zgpio commented 2 years ago

Please use hello world, and yarn add win32-api and add follow in src/main.ts

import { CS } from 'win32-api'

After this, execute yarn start, then you will find error.

waitingsong commented 2 years ago

2022-08-29_151550

It works node

tsc

waitingsong commented 2 years ago

Check the pkg size under node_modules:

2022-08-29_152827

zgpio commented 2 years ago

image

Can you reproduce this problem?

waitingsong commented 2 years ago

Fixed it with new version and config. wait a moment.

waitingsong commented 2 years ago

Update:

package.json

  "dependencies": {
    "win32-api": "^20.0.0",
    "ffi-napi": "^4.0.3",
    "ref-napi": "^3.0.3",
    "ref-struct-di": "^1.1.1",
    "ref-union-di": "^1.0.1"
  }

tsconfig.json:

{
  "compilerOptions": {
   ......................
    "skipLibCheck": true
  },

}
zgpio commented 2 years ago

I have verified it, close it.