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

Vite crashes with an error when using yarn pnp + workspaces. #15910

Closed
7 tasks done
DiFuks opened this issue Feb 14, 2024 · 6 comments · Fixed by #15920
Closed
7 tasks done

Vite crashes with an error when using yarn pnp + workspaces. #15910

DiFuks opened this issue Feb 14, 2024 · 6 comments · Fixed by #15920
Labels
has workaround p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release

Comments

@DiFuks
Copy link

DiFuks commented Feb 14, 2024

Describe the bug

When using Vite starting from version 5.1.0-beta.4 + yarn workspaces + pnp, Vite crashes with an error: Error: Failed to scan for dependencies from entries: /Users/difuks/WebstormProjects/vite-workspaces-issue/app/index.html

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

../.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1374:21:
  1374 │         let result = await callback({
       ╵                      ^

at packageEntryFailure (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47932:17)
at resolvePackageEntry (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47929:5)
at tryNodeResolve (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47699:20)
at Context.resolveId (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47462:28)
at Object.resolveId (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:50655:64)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async resolve (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:50963:26)
at async file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:51148:34
at async requestCallbacks.on-resolve (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1374:22)
at async handleRequest (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:732:11)

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

../.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1293:20:
  1293 │       let promise = setup({
       ╵                     ^

at setup (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:51138:19)
at handlePlugins (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1293:21)
at buildOrContextImpl (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:979:5)
at Object.buildOrContext (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:788:5)
at /Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:2223:68
at new Promise (<anonymous>)
at Object.context (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:2223:27)
at Object.context (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:2048:58)
at prepareEsbuildScanner (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:50915:26)

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

index.ts:1:27:
  1 │ import { helloWorld } from 'shared';
    ╵                            ~~~~~~~~


at failureErrorWithLog (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1651:15)
at /Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1059:25
at runOnEndCallbacks (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1486:45)
at buildResponseToResult (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1057:7)
at /Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1069:9
at new Promise (<anonymous>)
at requestCallbacks.on-end (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:1068:54)
at handleRequest (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:732:17)
at handleIncomingPacket (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:757:7)
at Socket.readFromStdout (/Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/esbuild-npm-0.19.12-fb5a3a4313/node_modules/esbuild/lib/main.js:680:7)

3:42:37 PM [vite] Pre-transform error: Failed to resolve entry for package "shared". The package may have incorrect main/module/exports specified in its package.json.
3:42:37 PM [vite] Internal server error: Failed to resolve entry for package "shared". The package may have incorrect main/module/exports specified in its package.json.
Plugin: vite:import-analysis
File: /Users/difuks/WebstormProjects/vite-workspaces-issue/app/index.ts
at packageEntryFailure (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47932:17)
at resolvePackageEntry (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47929:5)
at tryNodeResolve (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47699:20)
at Context.resolveId (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:47462:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.resolveId (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:50655:32)
at async TransformContext.resolve (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:50346:23)
at async normalizeUrl (file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:65286:34)
at async file:///Users/difuks/WebstormProjects/vite-workspaces-issue/.yarn/unplugged/vite-virtual-e8245c2587/node_modules/vite/dist/node/chunks/dep-2l_yqaZo.js:65448:47
at async Promise.all (index 0)

This issue only occurs when specifying peerDependencies in a child workspace. The problems are associated with this commit. If I revert to the old behavior, then in the variable root I get:

/Users/difuks/WebstormProjects/vite-workspaces-issue/app

With the new behavior, the path turns out like this:
/Users/difuks/WebstormProjects/vite-workspaces-issue

Reproduction

https://github.com/DiFuks/vite-workspaces-issue

Steps to reproduce

yarn
yarn dev

remove shared peerDependencies

yarn
yarn dev

System Info

System:
    OS: macOS 14.3.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 37.59 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    Yarn: 4.1.0 - ~/.nvm/versions/node/v18.19.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
  Browsers:
    Chrome: 121.0.6167.160
    Safari: 17.3.1

Used Package Manager

yarn

Logs

Show logs
vite:config using resolved config: {
  vite:config   root: '/Users/difuks/WebstormProjects/vite-workspaces-issue/app',
  vite:config   base: '/',
  vite:config   mode: 'development',
  vite:config   configFile: undefined,
  vite:config   logLevel: undefined,
  vite:config   clearScreen: undefined,
  vite:config   optimizeDeps: {
  vite:config     holdUntilCrawlEnd: true,
  vite:config     force: undefined,
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     host: undefined,
  vite:config     sourcemapIgnoreList: [Function: isInNodeModules$1],
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array], cachedChecks: true }
  vite:config   },
  vite:config   configFileDependencies: [],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     server: { host: undefined }
  vite:config   },
  vite:config   rawBase: '/',
  vite:config   resolve: {
  vite:config     mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   publicDir: '/Users/difuks/WebstormProjects/vite-workspaces-issue/app/public',
  vite:config   cacheDir: '/Users/difuks/WebstormProjects/vite-workspaces-issue/app/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   ssr: {
  vite:config     target: 'node',
  vite:config     optimizeDeps: { noDiscovery: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: false,
  vite:config   plugins: [
  vite:config     'vite:optimized-deps',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:client-inject',
  vite:config     'vite:css-analysis',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   css: { lightningcss: undefined },
  vite:config   esbuild: { jsxDev: true },
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     ssrEmitAssets: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true },
  vite:config     cssMinify: true
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   envDir: '/Users/difuks/WebstormProjects/vite-workspaces-issue/app',
  vite:config   env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(1) {
  vite:config     'fnpd_/Users/difuks/WebstormProjects/vite-workspaces-issue/app' => {
  vite:config       dir: '/Users/difuks/WebstormProjects/vite-workspaces-issue/app',
  vite:config       data: [Object],
  vite:config       hasSideEffects: [Function: hasSideEffects],
  vite:config       webResolvedImports: {},
  vite:config       nodeResolvedImports: {},
  vite:config       setResolvedCache: [Function: setResolvedCache],
  vite:config       getResolvedCache: [Function: getResolvedCache]
  vite:config     },
  vite:config     set: [Function (anonymous)]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +3ms
  vite:deps Hash is consistent. Skipping. Use --force to override. +0ms

Validations

@sapphi-red sapphi-red added has workaround p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release labels Feb 15, 2024
@sapphi-red
Copy link
Member

sapphi-red commented Feb 15, 2024

It seems that yarn pnp doesn't work with server.fs.cachedChecks: true (we enabled this by default since 5.1.0).
yarnpkg/berry#2959
For now, setting it to false would work.

@patak-dev
Copy link
Member

Bummer. @sapphi-red should we disabled cachedChecks if we detect yarn pnp for now?

@sapphi-red
Copy link
Member

@patak-dev Yeah, I think we should disable it for now.

@DiFuks
Copy link
Author

DiFuks commented Feb 15, 2024

Is there any point in always disabling cachedChecks for yarn pnp? Or only in cases where workspaces are used?

@patak-dev
Copy link
Member

I think we can disable it by default for pnp in general. People can opt-in if they want

@rgischk
Copy link

rgischk commented Feb 17, 2024

I ran into this issue yesterday, the specificity of this issue (pnp + workspaces + peerDependencies + vite 5.1) made this really difficult to reproduce and track down. I almost went crazy until I found this issue. Thank you guys for finding and fixing this, can'
t wait for the next patch.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has workaround p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants