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

Gentype: error TS2307: Cannot find module XXX or its corresponding type declarations. #6521

Closed
mununki opened this issue Dec 12, 2023 · 16 comments

Comments

@mununki
Copy link
Member

mununki commented Dec 12, 2023

Since v11-rc.5, the annotation for the linter of output seems changed

// rc.4
// @ts-ignore: Implicit any on import
import * as AddressSelectBS__Es6Import from './AddressSelect';

// rc.5
/* eslint-disable */
/* tslint:disable */

import * as AddressSelectBS__Es6Import from './AddressSelect';

This causes the TS error TS2307: Cannot find module XXX or its corresponding type declarations.

@mununki
Copy link
Member Author

mununki commented Dec 12, 2023

PR #6516 should fix this issue.

@cometkim
Copy link
Member

cometkim commented Dec 14, 2023

This causes the TS error TS2307: Cannot find module XXX or its corresponding type declarations.

It was intended change and you should add "allowJs": true into your tsconfig.json

@mununki
Copy link
Member Author

mununki commented Dec 14, 2023

Actually, my tsconfig.json already has it.

@cometkim
Copy link
Member

Hmm, what value of moduleResolution then?

@mununki
Copy link
Member Author

mununki commented Dec 15, 2023

"moduleResolution": "node", This is a Next.js project.

@cometkim
Copy link
Member

It's an intended change from #6442 to check modules if resolvable as any instead of @ts-ignore (which doesn't check any file resolution)

@mununki Can you provide the full tsconfig.json you use?

@mununki
Copy link
Member Author

mununki commented Dec 15, 2023

{
  "compilerOptions": {
    "paths": {
      "@assets/*": [
        "./src/*"
      ],
      "@components/*": [
        "./@components/*"
      ],
      "@pages/*": [
        "./pages/*"
      ],
      "@utils": [
        "./@utils"
      ]
    },
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "noEmit": true,
    "incremental": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

@cometkim
Copy link
Member

cometkim commented Dec 15, 2023

I think you explicitly excluded *.js files right? (by specifying the include with only ts files)

@cometkim
Copy link
Member

Hmm, I cannot reproduce the error even with the same tsconfig.json you provide.

It's weird because it is necessary to checking the gentype outputs is correct in TypeScript. That means you have actually incorrect files generated.

@cometkim
Copy link
Member

cometkim commented Dec 15, 2023

I can see incremental: true in your config. Can you make sure the clean build is not working? you should remove *.tsbuildinfo before changing the config and testing the build again.

@mununki
Copy link
Member Author

mununki commented Dec 15, 2023

I remove *.tsbuildinfo and build again, but still same.

I found the ts error seems gone if I change the *.gen.tsx:

// AddressSelect.gen.tsx

// Error
import * as AddressSelectBS from './AddressSelect';

// Ok
import * as AddressSelectBS from './AddressSelect.mjs'; // add '.mjs'

Any related?

@cometkim
Copy link
Member

cometkim commented Dec 15, 2023

That sounds like you are actually not using the node moduleResolution.

Specifying gentypeconfig.moduleResoultion to node16 or bundler in your rescript.json is going to solve your issue then.

@mununki
Copy link
Member Author

mununki commented Dec 18, 2023

I've tried node16 and bundler but no gain.

@mununki
Copy link
Member Author

mununki commented Dec 18, 2023

FYR, my rescript.json

{
  "name": "farmmoa-web",
  "version": "0.1.0",
  "jsx": {
    "version": 4,
    "mode": "automatic"
  },
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    }
  ],
  "package-specs": [
    {
      "module": "es6",
      "in-source": true
    }
  ],
  "suffix": ".mjs",
  "namespace": false,
  "pinned-dependencies": [],
  "bs-dependencies": [],
  "bs-dev-dependencies": [],
  "ppx-flags": [],
  "warnings": {
    "error": true,
    "number": "-48"
  },
  "bsc-flags": [
    "-open RescriptCore"
  ],
  "gentypeconfig": {
    "language": "typescript",
    "shims": {},
    "generatedFileExtension": ".gen.tsx",
    "module": "es6",
    "moduleResoultion": "node16",
    "debug": {
      "all": false,
      "basic": false
    }
  }
}

@glennsl
Copy link
Contributor

glennsl commented Dec 18, 2023

There's a typo. moduleResoultion should be moduleResolution.

@mununki
Copy link
Member Author

mununki commented Dec 18, 2023

Oops! I confirm that "node16" and "bundler" fix the issue.
Thanks!

@mununki mununki closed this as completed Dec 18, 2023
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

3 participants