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

Error Bun link: No overload matches this call #927

Open
warcayac opened this issue Nov 28, 2024 · 0 comments
Open

Error Bun link: No overload matches this call #927

warcayac opened this issue Nov 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@warcayac
Copy link

What version of Elysia is running?

1.1.25

What platform is your computer?

Linux 6.12.1-zen1-1-zen x86_64 unknown

What steps can reproduce the bug?

This is an update of this issue

I'm trying to create a very basic plugin for ElysiaJS, the project for this plugin is located at: ~/Projects/Programming/Bun/_packages/wac-demo/

The project structure is:

.
├── dist
├── node_modules
├── src
│   └── index.ts
├── .gitignore
├── build.ts
├── bun.lockb
├── package.json
├── README.md
├── tsconfig.dts.json
└── tsconfig.json

tsconfig.json

{
    "compilerOptions": {
        // Enable latest features
        "lib": ["ESNext", "DOM"],
        "target": "ESNext",
        "module": "ESNext",
        "moduleDetection": "force",
        "jsx": "react-jsx",
        "allowJs": true,

        // Bundler mode
        "moduleResolution": "bundler",
        "allowImportingTsExtensions": true,
        "verbatimModuleSyntax": true,
        "noEmit": true,

        // Best practices
        "strict": true,
        "skipLibCheck": true,
        "noFallthroughCasesInSwitch": true,

        // Some stricter flags (disabled by default)
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "noPropertyAccessFromIndexSignature": false,

        // Other
        "declaration": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "noUncheckedIndexedAccess": true
    }
}

tsconfig.dts.json

{
    "compilerOptions": {
        "preserveSymlinks": true,
        
        "target": "ES2022",
        "lib": ["ESNext"],

        "module": "ES2022",
        "rootDir": "./src",
        "moduleResolution": "bundler",
        "resolveJsonModule": true,

        "declaration": true,
        "emitDeclarationOnly": true,
        "outDir": "./dist",

        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,

        "strict": true,
        "skipLibCheck": true
    },
    "exclude": ["dist", "node_modules", "test", "build.ts"]
}

package.json

{
    "name": "wac-demo",
    "version": "0.1.0",
    "description": "A demo package for WAC",
    "author": {
        "name": "WAC",
        "email": "[email protected]"
    },
    "license": "MIT",
    "main": "./dist/cjs/index.js",
    "module": "./dist/index.mjs",
    "types": "./dist/index.d.ts",
    "exports": {
        "./package.json": "./package.json",
        ".": {
            "import": "./dist/index.mjs",
            "types": "./dist/index.d.ts",
            "require": "./dist/cjs/index.js"
        }
    },
    "scripts": {
        "build": "bun build.ts",
        "release": "npm run build && npm run test && npm publish --access public"
    },
    "devDependencies": {
        "@types/bun": "latest",
        "elysia": ">= 1.1.25",
        "tsup": "^8.3.5",
        "typescript": "^5.6.3"
    },
    "peerDependencies": {
        "elysia": ">= 1.1.25"
    }
}

build.ts

import { $ } from "bun";
import { build, type Options } from "tsup";

await $`rm -rf dist`;

const tsupConfig: Options = {
    entry: ["src/**/*.ts"],
    splitting: false,
    sourcemap: false,
    clean: true,
    bundle: true,
} satisfies Options;

await Promise.all([
    // ? tsup esm
    build({
        outDir: "dist",
        format: "esm",
        target: "node20",
        cjsInterop: false,
        ...tsupConfig,
    }),
    // ? tsup cjs
    build({
        outDir: "dist/cjs",
        format: "cjs",
        target: "node20",
        // dts: true,
        ...tsupConfig,
    }),
]);

await $`tsc --project tsconfig.dts.json`;

await Promise.all([$`cp dist/*.d.ts dist/cjs`]);

process.exit();

src/index.ts

import Elysia from "elysia";

export const mylogger = (showBody: boolean = false, showLog: boolean = true) => {
    const app = new Elysia({ name: "mylogger" });

    return app.as("plugin");
};

export default mylogger;

Files: tsconfig.dts.json, tsconfig.json, package.json, build.ts are based from official plugins: @elysiajs/static and @elysiajs/cors.

The following steps were done for current project:

$ bun run build
$ bun build.ts
CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v8.3.5
CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v8.3.5
CLI Target: node20
CLI Target: node20
CLI Cleaning output folder
CJS Build start
CLI Cleaning output folder
ESM Build start
CJS dist/cjs/index.js 1.85 KB
CJS ⚡️ Build success in 31ms
ESM dist/index.mjs 255.00 B
ESM ⚡️ Build success in 23ms

$ bun link
bun link v1.1.37 (8ca0eb83)
Success! Registered "wac-demo"

To use wac-demo in a project, run:
  bun link wac-demo

Or add it in dependencies in your package.json file:
  "wac-demo": "link:wac-demo"

Then I create another new project, for example at ~/Projects/Programming/Bun/ElysiaJS/SSR_React/react_ssr_example/,
and I add my local package with this command:

$ bun link wac-demo --save
[0.04ms] ".env"
bun link v1.1.37 (8ca0eb83)

installed wac-demo@link:wac-demo

1 package installed [10.00ms]

What is the expected behavior?

No error.

What do you see instead?

Screenshot_20241128_142801

This error is showed in editor:

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Elysia<"", false, { decorator: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, { schema: {}; macro: {}; macroFn: {}; }, {}, { derive: {}; resolve: {}; schema: MergeSchema<{}, {}>; }, { ...; }>' is not assignable to parameter of type 'Promise<{ default: AnyElysia; }>'.
      Type 'Elysia<"", false, { decorator: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, { schema: {}; macro: {}; macroFn: {}; }, {}, { derive: {}; resolve: {}; schema: MergeSchema<{}, {}>; }, { ...; }>' is missing the following properties from type 'Promise<{ default: AnyElysia; }>': then, catch, finally, [Symbol.toStringTag] ts(2769)

index.d.ts(887, 5): The last overload is declared here.

⚠ Error (TS2769) 
No overload matches this call.

The last overload gave the following error.
Argument of type:
  Elysia<
    "",
    false,
    { decorator: {}; store: {}; derive: {}; resolve: {} },
    { type: {}; error: {} },
    { schema: {}; macro: {}; macroFn: {} },
    {},
    { derive: {}; resolve:: {}; schema: MergeSchema<{}, {}> },
    { ...; }      
  >
  is not assignable to parameter of type Promise<{ default: AnyElysia }>

  Type:
  Elysia<
    "",
    false,
    { decorator: {}; store: {}; derive: {}; resolve: {} },
    { type: {}; error: {} },
    { schema: {}; macro: {}; macroFn: {} },
    {},
    { derive: {}; resolve:: {}; schema: MergeSchema<{}, {}> },
    { ...; }      
  >  

  is missing the following properties from type Promise<{ default: AnyElysia }> :
  - then
  - catch
  - finally
  [Symbol.toStringTag]

If I change the function signature of mylogger to this:

export const mylogger = async (showBody: boolean = false, showLog: boolean = true) => {..}

The error changes to this:

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Promise<Elysia<"", false, { decorator: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, { schema: {}; macro: {}; macroFn: {}; }, {}, { derive: {}; resolve: {}; schema: {}; }, { derive: {}; resolve: {}; schema: {}; }>>' is not assignable to parameter of type 'Promise<{ default: AnyElysia; }>'.
      Property 'default' is missing in type 'Elysia<"", false, { decorator: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, { schema: {}; macro: {}; macroFn: {}; }, {}, { derive: {}; resolve: {}; schema: {}; }, { derive: {}; resolve: {}; schema: {}; }>' but required in type '{ default: AnyElysia; }'.ts(2769)

index.d.ts(888, 9): 'default' is declared here.
index.d.ts(887, 5): The last overload is declared here.

⚠ Error (TS2769)
No overload matches this call.

  The last overload gave the following error.
  - Argument of type:
  
  Promise<
    Elysia<
      "",
      false,
      { decorator: {}; store: {}; derive: {}; resolve: {} },
      { type: {}; error: {} },
      { schema: {}; macro: {}; macroFn: {} },
      {},
      { derive: {}; resolve:: {}; schema: {} },
      { derive: {}; resolve:: {}; schema: {} }      
    >
  >
  
  is not assignable to parameter of type Promise<{ default: AnyElysia }>
  
  Property "default" is missing in type:

  Elysia<
    "",
    false,
    { decorator: {}; store: {}; derive: {}; resolve: {} },
    { type: {}; error: {} },
    { schema: {}; macro: {}; macroFn: {} },
    {},
    { derive: {}; resolve:: {}; schema: {} },
    { derive: {}; resolve:: {}; schema: {} }      
  >
  
  but required in type { default: AnyElysia }

Additional information

I've downloaded the source codes from official plugins: @elysiajs/static and @elysiajs/cors, and I've tried to use them as local packages by using bun link but I get the error messages.

So either this is an bug of bun link or I'm missing something, however I'm following the info provided here.

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant