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

Property 'initialize' does not exist after upgrading to v9.2.2 #3799

Closed
azat-io opened this issue Nov 14, 2022 · 20 comments · Fixed by #3802
Closed

Property 'initialize' does not exist after upgrading to v9.2.2 #3799

azat-io opened this issue Nov 14, 2022 · 20 comments · Fixed by #3802
Labels
Type: Bug / Error Something isn't working or is incorrect

Comments

@azat-io
Copy link

azat-io commented Nov 14, 2022

Description

I'm using mermaid with dynamic import:

let { initialize, render } = (await import('mermaid')).default

After updating to version 9.2.2 I get the following errors:

Property 'initialize' does not exist on type 'typeof import("/Users/user/Developer/azat-io/node_modules/.pnpm/mermaid@9.2.2/node_modules/mermaid/dist/mermaid")'.

32       let { initialize, render } = (await import('mermaid')).default

Property 'render' does not exist on type 'typeof import("/Users/user/Developer/azat-io/node_modules/.pnpm/mermaid@9.2.2/node_modules/mermaid/dist/mermaid")'.

32       let { initialize, render } = (await import('mermaid')).default

In version 9.2.1 everything works fine

@azat-io azat-io added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Nov 14, 2022
@sidharthv96
Copy link
Member

Can you share more info on your build setup and a minimal reproduction if possible?

@sidharthv96 sidharthv96 added Status: Awaiting Reply and removed Status: Triage Needs to be verified, categorized, etc labels Nov 15, 2022
@azat-io
Copy link
Author

azat-io commented Nov 15, 2022

@sidharthv96 I created demo repo:
https://github.com/azat-io/mermaid-ts-errors-9.2.2

  1. pnpm install
  2. pnpm test

@sidharthv96
Copy link
Member

//  tsconfig.json
-    "moduleResolution": "nodenext",
+    "moduleResolution": "node",

Seems to fix the issue.

@sidharthv96
Copy link
Member

sidharthv96 commented Nov 15, 2022

@aloisklink @knsv, changing "type": "module", in our package.json also fixes the problem.

Also, I was checking tslib, another dependency of docusaurus and they don't have a type in their package.json.
When I removed it from ours, EVERYTHING works.

// Webpack
const mermaid = require('mermaid');
import mermaid from 'mermaid';

// Vanilla
import mermaid from "mermaid";
let { initialize, render } = (await import("mermaid")).default;

So, why don't we just remove that from package.json (in mermaid)?

@azat-io
Copy link
Author

azat-io commented Nov 15, 2022

So, why don't we just remove that from package.json?

Because another package requires it.

Downgrading to v9.2.1 also fix problem.

@sidharthv96
Copy link
Member

@azat-io, I was actually talking about removing "type": "module", from the mermaid package, so it works for all downstream dependencies easily.

Will release v9.2.3 with this fix if there are no major issues with removing type from package.json.

@azat-io
Copy link
Author

azat-io commented Nov 15, 2022

Thanks. I'll wait v9.2.3

@sidharthv96 sidharthv96 linked a pull request Nov 15, 2022 that will close this issue
3 tasks
@sidharthv96
Copy link
Member

@azat-io can you try 9.2.3-rc.1 ?

@sidharthv96
Copy link
Member

Will release 9.2.3 once the issue is confirmed to be resolved.

@azat-io
Copy link
Author

azat-io commented Nov 16, 2022

@sidharthv96 I have updated mermaid to v9.2.3-rc1 and the problem is still there:
https://github.com/azat-io/mermaid-ts-errors-9.2.2

@aloisklink
Copy link
Member

@sidharthv96 I have updated mermaid to v9.2.3-rc1 and the problem is still there:
https://github.com/azat-io/mermaid-ts-errors-9.2.2

Confirmed, I'm having the same issue. If you disable noEmit and use // @ts-ignore to hide the TypeScript error, running the generated index,js file works fine, so this seems like an error in the types file.

@azat-io, can you try using "moduleResolution": "node" in your tsconfig.json file? That works for me.

The new "moduleResolution": "nodenext" (see https://www.typescriptlang.org/tsconfig#moduleResolution) was only recently added in TypeScript 4.7

It's possible that what you're currently seeing is a bug in TypeScript, since as far as I'm aware, we're copying exactly what TypeScript recommends, and our code works correctly in Node.JS, see https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs

I'm a bit unsure, TypeScript doesn't yet have the best documentation on how to make dual CommonJS/ESM packages.

@azat-io
Copy link
Author

azat-io commented Nov 16, 2022

Are you considering migration to pure ESM?

@aloisklink
Copy link
Member

Are you considering migration to pure ESM?

See #3590

I'm pretty for it, since it would make things a lot simpler.

Currently the CommonJS version of Mermaid only works because it bundles together all dependencies (some of them, like d3 are ESM only now). And making packages that are cross-compatible with both CommonJS and ESM is pretty easy if you're just targeting Node, but if you're targeting TypeScript + Node + every other potential bundler, it gets very complicated (e.g. we changed "type": "module" to "type": "commonjs" to fix another TypeScript issue, which then caused this TypeScript issue).

@sidharthv96
Copy link
Member

Weird, I tested with the locally modified package, and it was working fine. But the release version is failing for me too. Hmm....

sidharthv96 added a commit that referenced this issue Dec 1, 2022
* master:
  doc: Add mindmap integration docs
  fix: Fetch depth
  fix: Fetch depth
  fix: Fetch depth
  fix: Add commit count to release preview
  fix: Add commit count to release preview
  chore: Add working directory
  fix: release-preview-publish.yml
  Fix #3799: Remove `type` from package.json
@azat-io
Copy link
Author

azat-io commented Dec 1, 2022

Issue is relevant for version v9.2.3-rc.1

@azat-io
Copy link
Author

azat-io commented Dec 5, 2022

Why the issue was closed?

@sidharthv96 sidharthv96 reopened this Dec 6, 2022
@sidharthv96
Copy link
Member

I think GitHub auto-closed it because I had the issue number in my commit message.

@knsv knsv closed this as completed in 8cb6fbf Dec 15, 2022
@azat-io
Copy link
Author

azat-io commented Dec 15, 2022

I updated mermaid to v9.3.0 and issue was not fixed:
https://github.com/azat-io/mermaid-ts-errors-9.2.2

Can you reopen the issue again?

@sidharthv96 sidharthv96 reopened this Dec 15, 2022
@aloisklink
Copy link
Member

It looks like Mermaid v10 has fixed this issue, by switching to ESM-only and dropping CJS support!

I've tested this with azat-io/mermaid-ts-errors-9.2.2@9169ca8, I just changed Mermaid version in the package.json to point to Mermaid v10:

diff --git a/package.json b/package.json
index 1444aee..cd2e04d 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
   },
   "license": "ISC",
   "dependencies": {
-    "mermaid": "^9.3.0",
+    "mermaid": "^10.0.0",
     "typescript": "^4.8.4"
   }
 }

@aloisklink aloisklink mentioned this issue Apr 8, 2023
4 tasks
@azat-io
Copy link
Author

azat-io commented Apr 9, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants