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

Typescript Import issue with NodeNext #1327

Open
4 tasks done
aphex opened this issue Feb 4, 2023 · 8 comments
Open
4 tasks done

Typescript Import issue with NodeNext #1327

aphex opened this issue Feb 4, 2023 · 8 comments
Labels
Type: Improvement Includes backwards-compatible fixes typescript

Comments

@aphex
Copy link

aphex commented Feb 4, 2023

Reporting a bug?

When setting "moduleResolution": "NodeNext", in tsconfig.json and trying to use this package will result in a error in VSCode Could not find a declaration file for module 'vue-i18n'. However everything runs fine, I think this has to do with how exports are being interpreted

Changing the package.json exports to look like this seems to resolve the issue. Just adding types here as well. Is this a change that would be acceptable?

"exports": {
    ".": {
      "import": {
        "node": "./index.mjs",
        "default": "./dist/vue-i18n.esm-bundler.js"
      },
      "require": "./index.js",
      "types": "./dist/vue-i18n.d.ts"
    },
    "./dist/*": "./dist/*",
    "./index.mjs": "./index.mjs",
    "./package.json": "./package.json"
  },

Expected behavior

Package should not show dev time TS errors when using NodeNext moduleResolution

Reproduction

Quickest reproduction is to just create a TS vue app using Vite, and add vue-i8n to the project and update the tsconfig.json with "moduleResolution": "NodeNext",

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 25.84 GB / 31.31 GB
    Container: Yes
    Shell: 3.2.2 - /usr/bin/fish
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.1.3 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
  npmPackages:
    @intlify/unplugin-vue-i18n: ^0.8.1 => 0.8.1
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0
    vite: ^4.1.1 => 4.1.1
    vue: ^3.2.47 => 3.2.47
    vue-i18n: ^9.2.2 => 9.2.2
    vue-router: ^4.1.6 => 4.1.6
    vue-tsc: ^1.0.24 => 1.0.24

Screenshot

No response

Additional context

No response

Validations

@aphex aphex added the Status: Review Needed Request for review comments label Feb 4, 2023
@unshame
Copy link

unshame commented Feb 28, 2023

Faced the same issue, but patching vue-i18n's package.json doesn't seem to fix it completely, because now calling useI18n gets inferred as Composer<any, any, any, any, any, any>. I have to specify the return type explicitly. I don't really understand why.

Edit: ah, of course, the package.json of @intlify/core-base has to be patched as well, then the types work. I don't really understand why typescript doesn't fallback to the "types" or "typings" field in the root of package.json when it's missing in "exports".

@aphex
Copy link
Author

aphex commented Mar 20, 2023

Another update on this, updating to TS 5 and changing moduleResolution to bundler will result in a slightly different error.

Could not find a declaration file for module 'vue-i18n'. 'C:/path/to/node_modules/.pnpm/vue-i18n@9.2.2_vue@3.2.47/node_modules/vue-i18n/dist/vue-i18n.esm-bundler.js' implicitly has an 'any' type.
  There are types at 'c:/path/to/node_modules/vue-i18n/dist/vue-i18n.d.ts', but this result could not be resolved when respecting package.json "exports". The 'vue-i18n' library may need to update its package.json or typings.ts(7016)

Patching as I mentioned above still seems to fix this for me,

@Basaingeal
Copy link

Basaingeal commented Mar 20, 2023

Evan You is recommending on Twitter that Vue apps set moduleResolution to bundler when using TS 5.0, but that can't be done in apps using this library without setting "resolvePackageJsonExports": false currently because of the error mentioned above.

@kazupon kazupon added Type: Improvement Includes backwards-compatible fixes typescript and removed Status: Review Needed Request for review comments labels Mar 22, 2023 — with Volta.net
@RebeccaStevens
Copy link

RebeccaStevens commented Mar 27, 2023

"exports": {
    ".": {
      "import": {
        "node": "./index.mjs",
        "default": "./dist/vue-i18n.esm-bundler.js"
      },
      "require": "./index.js",
      "types": "./dist/vue-i18n.d.ts"
    },
    "./dist/*": "./dist/*",
    "./index.mjs": "./index.mjs",
    "./package.json": "./package.json"
  },

The "types" export needs to come first (for the same reason "default" needs to come last).
Additionally, each export should have its own type declaration file, (one for "imports" and one for "require") - this is because TypeScript can't tread a single file as both esm and cjs (and isn't smart enough to automatically switch between them).

A better fix would be:

"exports": {
    ".": {
      "import": {
        "types": "./dist/vue-i18n.d.ts",
        "node": "./index.mjs",
        "default": "./dist/vue-i18n.esm-bundler.js"
      },
      "require": {
        "types": "./dist/vue-i18n.d.cts", // Note: Different file to the one import points to
        "default": "./index.js"
      }
    },
    "./dist/*": "./dist/*",
    "./index.mjs": "./index.mjs",
    "./package.json": "./package.json"
  },

@Basaingeal
Copy link

"moduleResolution": "bundler" is now the default settings in the latest vuejs/tsconfig, compatible with TS 5.0.
https://github.com/vuejs/tsconfig#migrating-from-typescript--50

@lupas
Copy link

lupas commented May 1, 2023

Thanks @RebeccaStevens, that fixes it for me. I created an MR with your proposed changes: #1388

Until this is merged you can easily fix this for you locally with patch-package like so:

  1. Change node_modules/vue-i18n/package.json accordingly (see here)
  2. Run npx patch-package vue-i18n --exclude 'nothing'
  3. Add the following to scripts in your own package.json:
 "scripts": {
    "postinstall": "npx patch-package"
  }

And i18n is working with Typescript again nicely 😊

Related: microsoft/TypeScript#52363

@sodatea
Copy link

sodatea commented May 9, 2023

While the type isn't perfect with Node16 + ESM import, the bundler resolution mode already works with the latest 9.3 beta, but not with 9.2.2.

@kazupon
Copy link
Member

kazupon commented May 9, 2023

If you will avoid this issue, I would recommend installing the next tag version, (i.e. vue-i18n v9.3).
Currently in beta, this version has not changed much in terms of functionality from v9.2. Actually, It's used in nuxt i18n v8 beta.

Leuchak added a commit to clubcapra/clubcapra.github.io that referenced this issue Sep 3, 2023
tsconfig: disable resolvePackageJsonExports
tsconfig: set moduleResolution to "Bundler"

vue-i18n does not work with the parameters enabled.
intlify/vue-i18n#1327 (comment)
GLDuval pushed a commit to clubcapra/clubcapra.github.io that referenced this issue May 3, 2024
tsconfig: disable resolvePackageJsonExports
tsconfig: set moduleResolution to "Bundler"

vue-i18n does not work with the parameters enabled.
intlify/vue-i18n#1327 (comment)
patates-cipsi418 added a commit to clubcapra/clubcapra.github.io that referenced this issue Jun 8, 2024
* Remove old members and add Altium logo

* Update partners

* Remove old partner logo

* Change logo order

* Fix partner logos on mobile

* Fix homepage

* add vscode recommendation

* Setup vite + vuejs3 project

* Create the default route for /

* move img to src/assets/media

* config eslint ignore path

* install sass and @babel/types

* initialise the store in main.ts

* clear index.html

* create src/styles/settings.scss

* force i18n to use the CompositionApi

* add the NavbarComponent

* add the FooterComponent

* fix vue-i18n type's import for typescript 5

tsconfig: disable resolvePackageJsonExports
tsconfig: set moduleResolution to "Bundler"

vue-i18n does not work with the parameters enabled.
intlify/vue-i18n#1327 (comment)

* create the JumbotronVideoComponent

* Add all extern css and js librairies in index.html

* rename CapraLogoWhilte to capraLogoWhite

* implement ClientHolder

* Populate the Home page with the previous sections

* format index.html

* format style.min.css

* Add Animate on scroll library

* rename ClientHolder to SponsorHolderComponent

* move .jumbotron styles to the Jumbotron component

* remove id="section-featurettes" from HomeView

* move more jumbotron styles to Jumbotron component

* replace the carousel with a responsive grid

* defer script in index.html

* fix jumbotron text display

* compress video from original files in smaller size

* remove unnecessary id on HTMLElement

* Rename SponsorHolderComponent to SponsorComponent

* Fix the download button for the partenariat

* Create the MissionComponent

* replace link to /robots with router-link

* add more translation

* Import Contact and Competition

Co-authored-by: Mathieu Salois <mmmhsalois@users.noreply.github.com>

* use i18n for prototype_description

* reformat i18n trads

* update i18n in the mission and homeview

* replace a button with an anchor

* Allow background image in JumbotronVideoComponent

* Set img background in the CompetitionView

* update all img's src in CompetitionView

* Organise imports

* add SponsorItemComponent

* add i18n for robocuprescue

* move style.min.css into App.vue

* rename rrl.JPG to rrl_tmp.jpg

* rename rrl_tmp.jpg to rrl.jpg

* import bangkok img src to vuejs

* import dortmund img src to vuejs

* rename comp_team_2019.JPG to comp_team_2019_tmp.jpg

* rename comp_team_2019_tmp.jpg to comp_team_2019.jpg

* import sydney img src to vuejs

* separate competition with comments

* add i18n for ContactView.vue

* set anchor target to blank in ContactView.vue

* i18n competitions

* Add PartnersView.vue

* Import the partenariat plan in vuejs

* i18n discover_our_partnership

* Remap the current view in the NavbarComponent

* import all partners img in vuejs

* set img's alt attributes

* set the bg image in PartnersView.vue

* set partner anchor target to _blank

* Move partners.css into PartnersView.vue

* Create RessourcesView.vue

* import resources.html into RessourcesView.vue

* disable the bibbase script tag

* add link to the home page

* i18n RessourcesView.vue

* replace i18n `made with love` with `made_with_love`

* Replace the <script> tag with BibBaseComponent

* Create RobotsView.vue

* install vue-fullpage.js

* move robots.css into RobotsView.vue

* Complete RobotsView.vue

* Add background image in ContactView.vue

* Create TeamView.vue

* move avatar.css into TeamView.vue

* correct img path in TeamView.vue

* rename css' title class to member-title

* Create MemberItemComponent.vue

* Add the member list in comments

* group all members in their category

* Update all members

* install pinia-plugin-persistedstate

* delete old pages

* Add Bonzly Noel and William Jarry

* remove the dist folder

* i18n contact-us

* Remove the `EN` button in the navbar

* add matomo

* fix icon assets

* fix i18n for partners and competitions

* prefix .env's var with VITE_

* Replace the navbar with a DrawerComponent

* use createWebHistory instead of createWebHashHistory

* fix url /parners to /partners

* fix url /competition to /competitions

* Use breakpoints in jumbotron

* Fix favicon and page titles

* Use router to set title

* Move favicon back to assets

* Add imports

* add type declaration merging for RouteMeta

* move the router hook in its own page

* Use literal translation for page title

* Create deploy workflow

* Deploy after merge

* Add matomo

* Sets the GITHUB_TOKEN permissions

* Update program for Nicalas Vigneault

* delete 404.html

* Update deploy.yml to allow all routes to be served by index.html

* Update website URL in README.md

https://clubcapra.com -> https://www.clubcapra.com

* Delete unused files

* Fix heart icon

* Remove unused define option from vite.config.ts

* Update matomo setup in deploy.yml

* added z-index on bg-video

* Replace dev by div

* fix: toolbar hover color of buttons from red to white

* Remove the gap when dropping on robots page

* fix: removed absolute to bar, teleport to top when change page

Without the scrollBehavior, there were times where you were in the middle of the page when you switched between two, depending on how low you were in previous page

* Corrected width to use percents

All widths now use their correct percents instead of width: 0pt

* Changed static items to vue script

Languages used are now in a list and use a script to show progress bars for each

* Changed static items to vue script

Languages used are now in a list and use a script to show progress bars for each

* Bump postcss from 8.4.29 to 8.4.31 (#67)

* Bump postcss from 8.4.29 to 8.4.31

Bumps [postcss](https://github.com/postcss/postcss) from 8.4.29 to 8.4.31.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](postcss/postcss@8.4.29...8.4.31)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* npm upgrade

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Samuel Lachance <leuchak@slachance.ca>

* Fixed Appbar reacts weirdly to resizing the window
Fixes #69
Using vue conditionnal visibility and padding

* 2022 to 2023

* replace partnership plan for the new version

* added and deleted some members

* Removed unused image

* Added 2 new members and modified Max B's program

* Changed Jacob from ELE to LOG

* Bump vite from 4.4.11 to 4.4.12 (#76)

* Bump vite from 4.4.11 to 4.4.12

Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.4.11 to 4.4.12.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v4.4.12/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v4.4.12/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* upgrade package-lock

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Samuel Lachance <leuchak@slachance.ca>

* Deleted carlo gavazi and added stelpro as a sponso

* Added import of stelpro.png

* Named stelpro stelpro.

* Added capital to Stelpro

* Added Opnor to the list of sponsors and standardized capitalization for Stelpro

* removed random space that got into the code

* Added Hakko as silver sponsor

* Added monday as bronze tier sponsor

* Added odrive as bronze tier sponsor

* Fixed typo where the sponsor monday appears twice

* Changed member names & added new members & removed members

* Bump vite from 4.5.1 to 4.5.2 (#80)

Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.5.1 to 4.5.2.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v4.5.2/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v4.5.2/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* modified members list

* Add 2 tiers for sponsorships (Diamond and Platinum)

* temporary removal of the partnetship plan button

* changed sponsors tier list according to partnership plan

* Added a language chooser in the navbary

* Remvoe sponsorship buttons

* Change tint values on pictures and videos of markhor

* Added linkedin option in contact page

* Fix the translation not working on navbar

* Fix translating issues and button placement

* Hide new tiers for now

* Add missing end of line in i18n.ts

* Update section compétitions (#82)

* added Zwentendorf 2023 section

* rearranged comp section + bigger desc fonts

* Replace & with &amp;

---------

Co-authored-by: Samuel Lachance <leuchak@slachance.ca>

* Update ENRICH 2023 photos (zwentendorf)

* fix typo compe

* Add translation for teams page

* Fix typo

* Update TeamView.vue

* Update TeamView.vue

* Add tailwind and clean old code

* Add robot landing page animation

* Add navbar

* Add globe component

* Add past competition section

* Use videojs for enrich video

* Fix competition carousel on mobile

* Add team project cards and animations

* Add footer and sponsors

* Add link to contact footer

* Add translations

* Revert to youtube iframe

* Remove old videos

* Remove robots view

* Adjust globe sizing

* Update footer

* Fix footer

* Add translations

* Add competition tasks

* Start team page

* Add navbar links

* Add competition card translations

* Fix sm view

* Start new website

* Fix partners page

* Add publications page

* Remove unused pages

* Remove unused components

* Add locale change

* Add page titles

* Add new partner plan

* Remove unused pictures

* Remove unused deps

* Fix translation

* Add padding bottom to footer

* Update members

* Move members into data file

* Add partners into data file

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Samuel Lachance <leuchak@slachance.ca>
Co-authored-by: Mathieu Salois <mmmhsalois@users.noreply.github.com>
Co-authored-by: Denis <denis.turk2001@outlook.com>
Co-authored-by: Denis <81366683+patates-cipsi418@users.noreply.github.com>
Co-authored-by: JocobC <jacobclermont@live.ca>
Co-authored-by: JocobC <72584043+JocobC@users.noreply.github.com>
Co-authored-by: Raphael Vigneault <43865352+VignRaph@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mmmhsalois <mathieusalois@gmail.com>
Co-authored-by: McCaroon <nastyscaper@live.com>
Co-authored-by: McCaroon <43826975+McCaroon@users.noreply.github.com>
Co-authored-by: Simon St-Andre <simonstandre@gmail.com>
Co-authored-by: AntoineMaltais <159335607+AntoineMaltais@users.noreply.github.com>
Co-authored-by: Simon St-Andre <50240714+Flip-HH@users.noreply.github.com>
Co-authored-by: Nathan Gueissaz-Teufel <45826581+nathan-gt@users.noreply.github.com>
Co-authored-by: Nathan <nathan.gt.protic@gmail.com>
Co-authored-by: Benoit Malenfant <25072667+benmalenfant@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Includes backwards-compatible fixes typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants