server icon indicating copy to clipboard operation
server copied to clipboard

MODULE_NOT_FOUND Cannot find module 'vue'

Open romsar opened this issue 2 years ago • 18 comments

Hey After I setup SSR and run "node ssr.js" it throws errors like MODULE_NOT_FOUND Cannot find module 'vue'. I have only vue-server as prod dependency in package.json. All other packages are dev dependencies. Should I move Vue and other packages to dependencies from devDepencendies? p.s. I compile my assets in development env.

romsar avatar Jan 09 '22 14:01 romsar

Having the same issue more or less. Are you using vite, or webpack or what?

secondmanveran avatar Jan 17 '22 03:01 secondmanveran

Having the same issue more or less. Are you using vite, or webpack or what?

Webpack. I fix that problem by making dev dependencies available on production in package.json

romsar avatar Jan 17 '22 06:01 romsar

So you're saying you have node_modules installed in production servers? Or maybe I'm misunderstanding ...

secondmanveran avatar Jan 17 '22 06:01 secondmanveran

So you're saying you have node_modules installed in production servers? Or maybe I'm misunderstanding ...

I just moved my devDependencies to dependencies in package.json and now its working. That's happened probably because we compile our js & css assets somewhere else than inertia project folder (in my case its github actions).

Btw also you can try to remove externals: [webpackNodeExternals()], in webpack.mix.js - that should include vue and other vendors in your ssr.js, but in my case it does not work (i don't have much time to find why).

romsar avatar Jan 18 '22 14:01 romsar

I use Vite, not Webpack, but I do use Github Actions to compile all my assets for both my app and ssr but on my Ubuntu server it won't start up. Says it can't find vue.

I wonder if I need to somehow build a vendors javascript file that I can point the vue alias at for ssr? I'm really not understanding why it's not working.

secondmanveran avatar Jan 19 '22 01:01 secondmanveran

@RomanSarvarov

Can you be explicit please about which dev dependencies you moved to dependencies?

Nothing seems to work for me except actually installing node_modules on my server.

The SSR compilation should bundle all dependencies into the ssr.js file so that no other files are required to run. It's only loaded once, and done so via a background process so size isn't an issue.

secondmanveran avatar Feb 11 '22 08:02 secondmanveran