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

Imports fail with Vite #325

Open
Uninen opened this issue Jul 30, 2022 · 6 comments
Open

Imports fail with Vite #325

Uninen opened this issue Jul 30, 2022 · 6 comments
Assignees

Comments

@Uninen
Copy link

Uninen commented Jul 30, 2022

Imports from @microsoft/microsoft-graph-types and @microsoft/microsoft-graph-types-beta fail when using Vite, resulting in this error: [plugin vite:dep-scan] Failed to resolve entry for package "@microsoft/microsoft-graph-types-beta". The package may have incorrect main/module/exports specified in its package.json.

@ghost ghost added the ToTriage label Jul 30, 2022
@n1jmbt
Copy link

n1jmbt commented Aug 8, 2022

I have had this error before, and have it again now.

I have been able to work around it, by adding this to the package.json:

...
"main": "microsoft-graph.d.ts"
...

then running the project using npm run dev, and changing the file back to the original.

It somehow triggers the right re-scan.

@nikithauc nikithauc self-assigned this Aug 8, 2022
@ghost ghost removed the ToTriage label Aug 8, 2022
@nikithauc
Copy link
Contributor

nikithauc commented Aug 8, 2022

@Uninen Thank you for reporting this issue!

@n1jmbt I am curious to know what happens if main is set to empty -> main: ""?

@n1jmbt
Copy link

n1jmbt commented Aug 9, 2022

@n1jmbt I am curious to know what happens if main is set to empty -> main: ""?

Setting main to empty (""), does not work :(

I can can preproduce the error, by deleting my node_modules folder, and running npm install again.

@n1jmbt
Copy link

n1jmbt commented Aug 9, 2022

This is the full error, and is dubplicated for every file it is imported in, I have 6 identical errors

X [ERROR] [plugin vite:dep-scan] Failed to resolve entry for package "@microsoft/microsoft-graph-types". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@microsoft/microsoft-graph-types". The package may have incorrect main/module/exports specified in its package.json.

    node_modules/vite/dist/node/chunks/dep-c9998dc6.js:40970:10:
      40970      throw new Error(`Failed to resolve entry for package "${id}". ` +
                       ^

    at packageEntryFailure (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:40970:11)
    at resolvePackageEntry (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:40966:9)
    at tryNodeResolve (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:40773:20)
    at Context.resolveId (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:40581:28)
    at Object.resolveId (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:39254:55)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async resolve (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:39466:26)
    at async C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:39626:34
    at async callback (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:933:28)
    at async handleRequest (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:713:30)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39616:18:
      39616              build.onResolve({
                               ~~~~~~~~~

    at setup (C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:39616:19)
    at handlePlugins (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:855:23)
    at Object.buildOrServe (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:1149:7)
    at C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:2110:17
    at new Promise (<anonymous>)
    at Object.build (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:2109:14)
    at Object.build (C:\git\blf-teams-app\node_modules\esbuild\lib\main.js:1956:51)
    at C:\git\blf-teams-app\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:39414:54
    at Array.map (<anonymous>)

  The plugin "vite:dep-scan" was triggered by this import

    script:C:/git/blf-teams-app/src/components/UserCard.vue?id=0:19:7:
      19 │ import "@microsoft/microsoft-graph-types"
         ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
node_modules/vite/dist/node/chunks/dep-c9998dc6.js:40970:10: ERROR: [plugin: vite:dep-scan] Failed to resolve entry for package "@microsoft/microsoft-graph-types". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@microsoft/microsoft-graph-types". The package may have incorrect main/module/exports specified in its package.json.

@n1jmbt
Copy link

n1jmbt commented Aug 9, 2022

Same as these:

vitejs/vite#7754
vitejs/vite#7671
vitejs/vite#7725

@garth
Copy link

garth commented Feb 19, 2024

This is still a problem, but can be patched with pnpm patch.

pnpm patch @microsoft/[email protected]

Edit the package.json in the folder crated by pnpm patch and add

diff --git a/package.json b/package.json
index 2b5ae34595613d3ad60879b20479e8520c7d10af..822ba59e34cdef3f9b556040b0e5825332c3aa13 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
   "version": "2.40.0",
   "license": "MIT",
   "types": "microsoft-graph.d.ts",
+  "main": "microsoft-graph.d.ts",
   "scripts": {
     "test": "tsc && mocha spec/**.ts"
   },

The follow the instructions given by pnpm patch to apply the patch to all future installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants