slidevjs / slidev

Presentation Slides for Developers
https://sli.dev
MIT License
32.82k stars 1.33k forks source link

Don't force hoisting #1385

Closed cdtut closed 5 months ago

cdtut commented 7 months ago

Describe the bug

dev

[vite] Internal server error: Failed to resolve import "vue" from "../../../node_modules/.pnpm/@slidev+client@0.46.3_postcss@8.4.33_typescript@5.3.3_vite@5.0.12/node_modules/@slidev/client/main.ts?v=7928d2f5". Does the file exist?`

build

[vite]: Rollup failed to resolve import "vue" from "../../../node_modules/.pnpm/@slidev+client@0.46.3_postcss@8.4.33_typescript@5.3.3_vite@5.0.12/node_modules/@slidev/client/main.ts".`
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

Is there workaround? We can't use pnpm hoisting please consider workaround or let it work without hoisting otherwise can't use it because project cant be outside our monorepo.

No reason for project to need hoisting this requirement should be removed.

To Reproduce Use pnpm and start slidev in package in monorepo.

I use lot of vite based products that have lot of dependencies but vite does not have problem to find those in sub directory. They dont need to enable hoisting they work in default way.

Why it works in every product but not slidev? If you can help me understand I can try think solution.

In repo/packages/project/slideproject/node_modules I only see .bin, .vite, @slidev (with cli under it) and playwright-chromium. @slidev/cli and playwright-chromium are the only 2 dependencies I set in package.json.

Shouldn't all dependencies of slidev be in repo/packages/project/slideproject/node_modules or repo/packages/project/slideproject/node_modules/@slidev/cli/node_modules (but there is only .bin there)?

KermanX commented 7 months ago

This error is strange because there is already a CI for non-hoist use case: https://github.com/slidevjs/slidev/actions/workflows/smoke.yml?query=branch%3Amain

(e.g. non-hoist&PNPM&Windows: https://github.com/slidevjs/slidev/actions/runs/8191090886/job/22399525030)

Shouldn't all dependencies of slidev be in repo/packages/project/slideproject/node_modules or repo/packages/project/slideproject/node_modules/@slidev/cli/node_modules (but there is only .bin there)?

I think that's because you are using PNPM. All non-hoist PNPM node_modules looks like this.

antfu commented 7 months ago

We temporarily closed this due to the lack of enough information. We could not identify whether it was a bug or a userland misconfiguration with the given info. Please provide a minimal reproduction to reopen the issue. Thanks.

Why reproduction is required

cdtut commented 6 months ago

@KermanX Is there demo slidev project I can use that already work with non-hoist PNPM? I can modify that to narrow down the cause.

KermanX commented 6 months ago

Is there demo slidev project I can use that already work with non-hoist PNPM? I can modify that to narrow down the cause.

Here is a monorepo & non-hoist example: https://github.com/KermanX/temp-slidev-project-3-10

Works well on my Windows machine

cdtut commented 6 months ago

@KermanX I tried linux and pnpm 8.15.4. dev command runs fine but when load the web page it's blank screen and this error happens in console.

4:27:32 PM [vite] Internal server error: Failed to resolve import "@vueuse/core" from "node_modules/.vite/deps/chunk-MJVIJ6GD.js?v=5130af76". Does the file exist?
  Plugin: vite:import-analysis
  File: /temp-slidev-project-3-10/slides/node_modules/.vite/deps/chunk-MJVIJ6GD.js?v=5130af76:76:99
  74 |  // ../node_modules/.pnpm/@vueuse+motion@2.1.0_vue@3.4.21/node_modules/@vueuse/motion/dist/index.mjs
  75 |  import { ref, unref, watch, computed, reactive, defineComponent, useSlots, h, resolveComponent, onUpdated, isRef } from "vue";
  76 |  import { isObject, useEventListener, useIntersectionObserver, unrefElement, useMediaQuery } from "@vueuse/core";
     |                                                                                                    ^
  77 |  import { tryOnUnmounted } from "@vueuse/shared";
  78 |  
      at formatError (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:50545:46)
      at TransformContext.error (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:50539:19)
      at normalizeUrl (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:65623:33)
      at async file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:65778:47
      at async Promise.all (index 2)
      at async TransformContext.transform (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:65699:13)
      at async Object.transform (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:50854:30)
      at async loadAndTransform (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:53644:29)
      at async viteTransformMiddleware (file:///temp-slidev-project-3-10/node_modules/.pnpm/vite@5.1.5/node_modules/vite/dist/node/chunks/dep-G-px366b.js:63438:32)

Exact steps

git clone https://github.com/KermanX/temp-slidev-project-3-10
cd temp-slidev-project-3-10
pnpm install
cd slides
pnpm run dev slides.md
cdtut commented 6 months ago

@KermanX in earlier slidev dev and build failed but in 0.48.1 build is working. For you too?

cdtut commented 6 months ago

@KermanX Is dev working for you?

KermanX commented 6 months ago

Additional information:

AlbertBrand commented 5 months ago

A workaround that I found is to partially hoist @vueuse/*. Create an .npmrc file with the contents:

public-hoist-pattern[]=@vueuse/*

And re-run pnpm install. Then all @vueuse packages are symlinked in node_modules which plays nice with Vite.