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

Module: Support ES Modules and TypeScript, with no training wheels (moduleResolution: Node16) #3159

Open
FossPrime opened this issue Oct 25, 2022 · 3 comments
Assignees
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Milestone

Comments

@FossPrime
Copy link

FossPrime commented Oct 25, 2022

Describe the feature you would like to see added

To avoid ambiguity with imports, support better tree shaking, top level async-await and compatibility problems between packages and tooling, we need to use Node16 mode in TS moduleResolution.

PrimeVue is currently very broken with direct Node16 resolution.

  1. The package.json files don't define exports using standard ES Module semantics, but instead rely on the "module" property whose behavior is not standardized in NPM at the top level of package.json, only in exports.
  2. The d.ts type definitions use correct default export syntax, but the ESM file uses incorrect export { PrimeVue as default, usePrimeVue } which relies on spotty and unpredictable synthetic import compatibility poly-fills... this package is running into the pitfalls of relying on that.
  3. The standard, main entry point property currently points to a CJS module... which is incapable of using standard ESM default exports without webpack hacks that doesn't work on esbuild/vite/rollup.

CF: https://stackblitz.com/~/github.com/FossPrime/bug-primevue-esm-types
SBC: https://stackblitz.com/edit/public-sakai-yqyw2y?file=src%2Fmain.ts%3AL13,src%2Fvite-env.d.ts%3AL11

This is currently not a big deal as TS Support for "moduleResolution": "Node16" has some pitfalls in Vite 3.1, however there is a work being done to fix the plugins/docs, official support may come Vite 3.2/3.3.

Is your feature request related to a problem?

Screenshot from 2022-10-25 11-42-38

Describe the solution you'd like

Define exports, like the Vite plugin does https://unpkg.com/browse/@vitejs/[email protected]/package.json

And define default exports types correctly, using export default in both the type definition and the ESM code

Describe alternatives you have considered

  1. Fork v3 like I did for v2
  2. Write my own definitions for all components like I began to do in the sandbox.

Additional context

Somewhat related to #2847

@FossPrime FossPrime added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Oct 25, 2022
@pwang2
Copy link

pwang2 commented Dec 13, 2022

Is there any follow up on this? As the new year 2023's approaching, we all are thinking about updating our tsconfig.json to be moduleResolution: "NodeNext".

@cjholowatyj
Copy link

Any progress on this? TIA

@XavierVilaRubio
Copy link

After almost a year and a half this got 0 attention? 🥲
I'm trying to build a project with this tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "outDir": "dist",
    "sourceMap": true,

    "strict": false,
    "jsx": "preserve",

    "lib": ["es2022", "dom", "dom.iterable"],
    "types": ["vite/client"]
  },
  "include": ["./src/**/*"]
}

and I'm getting TS2307: Cannot find module 'primevue/config' or its corresponding type declarations. on build step...

Any idea on how to solve it?

@mertsincan mertsincan added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add labels Dec 27, 2024
@mertsincan mertsincan self-assigned this Dec 27, 2024
@mertsincan mertsincan added this to the 4.3.0 milestone Dec 27, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeVue Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
Status: Review
Development

No branches or pull requests

5 participants