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

Unable to discover some of npm dependencies #15823

Closed
bartlomieju opened this issue Sep 8, 2022 · 1 comment · Fixed by #16561
Closed

Unable to discover some of npm dependencies #15823

bartlomieju opened this issue Sep 8, 2022 · 1 comment · Fixed by #16561
Labels
bug Something isn't working correctly node compat

Comments

@bartlomieju
Copy link
Member

Best seen in an example here: #15427 (comment)

Concretely:

// vite.config.js
import { defineConfig } from 'npm:vite'
import vue from 'npm:@vitejs/plugin-vue'
import "npm:vue@3.2.37/compiler-sfc" // <--- this step is not required when running in Node

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()]
})

In the above example vue is a peer dependency of @vitejs/plugin-vue. However, if we try to run to run a project without that import we get following error:

Download https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-3.1.0.tgz
error when starting dev server:
Error: Failed to resolve vue/compiler-sfc.
@vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree.
    at resolveCompiler (file:///Users/ib/Library/Caches/deno/npm/registry.npmjs.org/@vitejs/plugin-vue/3.1.0/dist/index.mjs:12:11)
    at Context.buildStart (file:///Users/ib/Library/Caches/deno/npm/registry.npmjs.org/@vitejs/plugin-vue/3.1.0/dist/index.mjs:2587:46)

Due to how Deno currently discovers and handles npm dependencies, we are not installing vue package that is required to run this program.

@bartlomieju bartlomieju added bug Something isn't working correctly node compat labels Sep 8, 2022
@bartlomieju
Copy link
Member Author

One solution to this problem might be that all npm:<specifier> references present in the import map could be downloaded upfront. This could play nicely with set up scripts that various tools provide that scaffold a project for the user.

dsherret added a commit that referenced this issue Nov 8, 2022
This adds support for peer dependencies in npm packages.

1. If not found higher in the tree (ancestor and ancestor siblings),
peer dependencies are resolved like a dependency similar to npm 7.
2. Optional peer dependencies are only resolved if found higher in the
tree.
3. This creates "copy packages" or duplicates of a package when a
package has different resolution due to peer dependency resolution—see
https://pnpm.io/how-peers-are-resolved. Unlike pnpm though, duplicates
of packages will have `_1`, `_2`, etc. added to the end of the package
version in the directory in order to minimize the chance of hitting the
max file path limit on Windows. This is done for both the local
"node_modules" directory and also the global npm cache. The files are
hard linked in this case to reduce hard drive space.

This is a first pass and the code is definitely more inefficient than it
could be.

Closes #15823
bartlomieju pushed a commit that referenced this issue Nov 8, 2022
This adds support for peer dependencies in npm packages.

1. If not found higher in the tree (ancestor and ancestor siblings),
peer dependencies are resolved like a dependency similar to npm 7.
2. Optional peer dependencies are only resolved if found higher in the
tree.
3. This creates "copy packages" or duplicates of a package when a
package has different resolution due to peer dependency resolution—see
https://pnpm.io/how-peers-are-resolved. Unlike pnpm though, duplicates
of packages will have `_1`, `_2`, etc. added to the end of the package
version in the directory in order to minimize the chance of hitting the
max file path limit on Windows. This is done for both the local
"node_modules" directory and also the global npm cache. The files are
hard linked in this case to reduce hard drive space.

This is a first pass and the code is definitely more inefficient than it
could be.

Closes #15823
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant