msgraph-typescript-typings icon indicating copy to clipboard operation
msgraph-typescript-typings copied to clipboard

Imports fail with Vite

Open Uninen opened this issue 3 years ago • 6 comments

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.

Uninen avatar Jul 30 '22 16:07 Uninen

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.

n1jmbt avatar Aug 08 '22 11:08 n1jmbt

@Uninen Thank you for reporting this issue!

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

nikithauc avatar Aug 08 '22 22:08 nikithauc

@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 avatar Aug 09 '22 08:08 n1jmbt

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 avatar Aug 09 '22 08:08 n1jmbt

Same as these:

https://github.com/vitejs/vite/issues/7754 https://github.com/vitejs/vite/issues/7671 https://github.com/vitejs/vite/issues/7725

n1jmbt avatar Aug 09 '22 08:08 n1jmbt

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.

garth avatar Feb 19 '24 15:02 garth