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

could not resolve vue-demi (Nuxt 3 deployment on netlify) #847

Closed
Joaojack opened this issue Oct 15, 2021 · 6 comments
Closed

could not resolve vue-demi (Nuxt 3 deployment on netlify) #847

Joaojack opened this issue Oct 15, 2021 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Joaojack
Copy link

Joaojack commented Oct 15, 2021

Hi team,
got this error when trying to deploying (for testing) a Nuxt 3 app with vue-use
4:25:43 PM: > .netlify/functions-internal/server/node_modules/@vueuse/shared/index.mjs:636:14: error: Could not resolve "vue-demi" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time) 4:25:43 PM: 636 │ require("vue-demi").set(...args); 4:25:43 PM: ╵ ~~~~~~~~~~ 4:25:43 PM: .netlify/functions-internal/server/node_modules/vue-demi/package.json:18:17: note: The module "./lib/index.cjs" was not found on the file system 4:25:43 PM: 18 │ "require": "./lib/index.cjs", 4:25:43 PM: ╵ ~~~~~~~~~~~~~~~~~ 4:25:43 PM:

@antfu
Copy link
Member

antfu commented Oct 15, 2021

Can you share a minimal reproduction? Thanks.

@Joaojack
Copy link
Author

Joaojack commented Oct 15, 2021

Of course, sorry i'm still a beginner. Here is my repo : https://github.com/Joaojack/Nuxt3-x-tailwindcss-app-example
FYI it works fine on localhost, no problem when running npm run dev or npm run build here.
On Netlify my build command is nuxt build, and the publish repository is dist.

@antfu antfu added bug Something isn't working and removed needs reproduction labels Oct 15, 2021
@Joaojack
Copy link
Author

Joaojack commented Oct 17, 2021

Here is a more precise view of the error if it can help https://i.imgur.com/KI5dKuZ.png

@antfu
Copy link
Member

antfu commented Oct 18, 2021

I guess this is because Netlify functions do not run the postinstall hook that vue-demi relies on. Need some help if anyone knows better of how to fix this.

@antfu antfu added the help wanted Extra attention is needed label Oct 18, 2021
@didavid61202
Copy link

didavid61202 commented Oct 23, 2021

hacky fix:
change Netlify's build command to yarn build && cp node_modules/vue-demi/lib/index.cjs .netlify/functions-internal/server/node_modules/vue-demi/lib/index.cjs. which copy index.cjs from root node-modules to server node_modules.

@antfu seems like when we build .output/ locally with nitro (which is trim by @vercel/nft to keep only used files in node_module?), .output/server/vue-demi/lib/index.cjs was kept. But when build on Netlify, .output/server/vue-demi/lib/index.mjs was kept instead of .cjs (cause by change of import/require statement difference locally vs on Netlify?)

not sure why it's the case, maybe someone knows more about module system could help. Thanks!

@Joaojack
Copy link
Author

Joaojack commented Oct 23, 2021

@didavid61202 your hacky fix worked indeed for me thanks :)

@antfu antfu closed this as completed in 251e663 Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants