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

Fail to import default from a commonjs package like hammerjs from a file in node_modules with optimizeDeps.exclude config #17717

Closed
7 tasks done
Jinjiang opened this issue Jul 19, 2024 · 1 comment

Comments

@Jinjiang
Copy link
Contributor

Jinjiang commented Jul 19, 2024

Describe the bug

  • import * as Hammer from "hammerjs"; in source file works,
  • import Hammer from "hammerjs"; in source file works,
  • import * as Hammer from "hammerjs"; in an npm package works,
  • import Hammer from "hammerjs"; in an npm package works,
  • import * as Hammer from "hammerjs"; in an npm package with optimizeDeps.exclude config works, however,
  • import Hammer from "hammerjs"; in an npm package with optimizeDeps.exclude config doesn't work

Reproduction

https://github.com/Jinjiang/reproductions/tree/vite-deps-20240719

Steps to reproduce

pnpm install
pnpm dev

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M1
    Memory: 66.92 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.local/share/mise/installs/node/20/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 10.2.4 - ~/.local/share/mise/installs/node/20/bin/npm
    pnpm: 9.5.0 - ~/Library/pnpm/pnpm
    bun: 1.0.29 - ~/.local/share/mise/installs/bun/latest/bin/bun
  Browsers:
    Safari: 18.0
  npmPackages:
    vite: ^5.3.4 => 5.3.4

Used Package Manager

pnpm

Logs

Uncaught SyntaxError: The requested module '/node_modules/.pnpm/hammerjs@2.0.8/node_modules/hammerjs/hammer.js?v=cd432710' does not provide an export named 'default' (at index.js:2:8)

Validations

@Jinjiang Jinjiang changed the title Fail to import default from a commonjs package like hammerjs in node_modules with optimizeDeps.exclude config Fail to import default from a commonjs package like hammerjs from a file in node_modules with optimizeDeps.exclude config Jul 19, 2024
@Jinjiang
Copy link
Contributor Author

Update: I've found adding the main file of foo into optimizeDeps.entries can make it works. Problem solved.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant