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

bug: Not supported for use in TypeScript, the default export init is not of function type. #5

Closed
rxliuli opened this issue Jun 3, 2024 · 2 comments · Fixed by #6
Closed

Comments

@fengkx
Copy link
Owner

fengkx commented Jun 3, 2024

Typescript resolve to main filed of package.json by default which is the entrypoint for Node.js. It doesn't have(require) a init function.
https://www.typescriptlang.org/play/?target=99#code/JYWwDg9gTgLgBMAdsGAaOBvAxgVxgXzgDMoIQ4ByAK2AFMAjAQwFoB3RgZxAHowBrAObdWDbjQaMA+lA6T2XCgG4AUI3YoEyGAAoAlMuVA

import from the web entrypoint will fix the problem. I don't know how to make typecript use browser field for now.

@rxliuli
Copy link
Contributor Author

rxliuli commented Jun 5, 2024

Typescript resolve to main filed of package.json by default which is the entrypoint for Node.js. It doesn't have(require) a init function. https://www.typescriptlang.org/play/?target=99#code/JYWwDg9gTgLgBMAdsGAaOBvAxgVxgXzgDMoIQ4ByAK2AFMAjAQwFoB3RgZxAHowBrAObdWDbjQaMA+lA6T2XCgG4AUI3YoEyGAAoAlMuVA

import from the web entrypoint will fix the problem. I don't know how to make typecript use browser field for now.

The npm package you published lacks the types field in its package.json. Link to the package.json

I'm not sure about your build process, but you need to declare the exports field in the package.json and use different entry points and type definitions for different environments. Refer to the Node.js documentation

Here is an example:

// package.json
{
  "exports": {
    ".": {
      "require": {
        "types": "pkg/nodejs/jieba_rs_wasm.d.ts",
        "default": "pkg/nodejs/jieba_rs_wasm.js"
      },
      "node": {
        "types": "pkg/nodejs/jieba_rs_wasm.d.ts",
        "default": "pkg/nodejs/jieba_rs_wasm.js"
      },
      "browser": {
        "types": "pkg/web/jieba_rs_wasm.d.ts",
        "default": "pkg/web/jieba_rs_wasm.js"
      }
    }
  }
}

rxliuli added a commit to rxliuli/jieba-wasm that referenced this issue Jun 5, 2024
@fengkx fengkx closed this as completed in #6 Jun 7, 2024
fengkx added a commit that referenced this issue Jun 7, 2024
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

Successfully merging a pull request may close this issue.

2 participants