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

module cannot import other modules if it in node_modules #7775

Closed
7 tasks done
scx567888 opened this issue Apr 17, 2022 · 3 comments
Closed
7 tasks done

module cannot import other modules if it in node_modules #7775

scx567888 opened this issue Apr 17, 2022 · 3 comments

Comments

@scx567888
Copy link

Describe the bug

I write a lib
if it in project it`s work
but if i publish to npm and install it
it cannot import other modules

Reproduction

https://github.com/scx567888/error-example1

System Info

windows 10                 19044.1645
node                       16.14.2
vite                       2.9.5
@vitejs/plugin-vue         2.3.1
edge                       100

Used Package Manager

npm

Logs

No response

Validations

@scx567888
Copy link
Author

scx567888 commented Apr 17, 2022

https://github.com/scx567888/error-example1

1, run project it`s work
2, copy _node_modules/my-lib to node_modules (simulated npm i mylib)
3, In src/main.js comment out 6 line and uncommenting 10 line
4, run project you will see error

@scx567888
Copy link
Author

scx567888 commented Apr 18, 2022

i try add optimizeDeps.include to vite.config.js it work . but why?

@bluwy
Copy link
Member

bluwy commented Apr 18, 2022

I'm assuming you add spark-md5 to optimizeDeps.include, which made it work. The reason it doesn't work out-of-the-box is because Vite doesn't handle Vue files in third-party libraries currently, similar to #3910. A workaround for now is to have my-lib pre-compile Vue files to JS so that everything can be bundled.

Until Vite or plugin-vue supports Vue files in libraries (which is possible with #6801 though experimental), the workaround is actually the expected behaviour. I'll close this at the meantime so we can track in #3910 instead.

@bluwy bluwy closed this as completed Apr 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2022
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

2 participants