Nuxt App Doesn't Render When Used Inside Single-SPA
See original GitHub issueHi, I’m trying to use your project to turn my Nuxtjs app into a micro frontend. I’ve configured my app to generate one bundle file called main.js. When I load this main.js into single-spa, I get no DOM. I do have an index root (pages/index.vue). Is there something else I need to include inside single-spa for this app to render?
Part of my single-spa:
<script type="systemjs-importmap">
{ "imports": {
"someRandomName": "http://localhost:3000/_nuxt/main.js",
...
}
</script>
Now, I do see the lifecycle hooks firing. My mfe.js is exactly what’s provided in the example directory and I do see messages like Nuxt bootstrapped, so I can see the lifecycle hooks are working.
The issue is nothing is rendering in the DOM.
Here is my nuxt.config.js:
import colors from 'vuetify/es5/util/colors'
const bodyParser = require("body-parser");
export default {
render: {
resourceHints: false
},
serverMiddleware: [
bodyParser.json(), // Register JSON middleware so we can handle application/json requests.
{path: "/deliver", handler: "~/serverMiddleware/deliver.js"},
{path: "/save", handler: "~/serverMiddleware/save.js"}
],
mode: "spa",
/*
** Headers of the page
*/
head: {
title: 'test',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: [
],
/*
** Plugins to load before mounting the App
*/
plugins: [
{src:'~/plugins/v-jsoneditor', mode:'client'},
{src: "~/plugins/localStorage.js", ssr: false}
],
/*
** Nuxt.js dev-modules
*/
buildModules: [
'@nuxtjs/vuetify',
'cookie-universal-nuxt' ,
['@femessage/nuxt-micro-frontend', {force: true}]
],
/*
** Nuxt.js modules
*/
modules: [
'@nuxtjs/axios',
'nuxt-graphql-request',
'cookie-universal-nuxt' ,
['@femessage/nuxt-micro-frontend', {force: true}]
],
graphql: {
/**
* Your GraphQL endpoint (required)
*/
endpoint: 'https://swapi-graphql.netlify.com/.netlify/functions/index',
/**
* Enable support for AST
* default: false
*/
AST: false,
/**
* Options
* See: https://github.com/prisma-labs/graphql-request
*/
options: {},
},
axios:{
},
/*
** vuetify module configuration
** https://github.com/nuxt-community/vuetify-module
*/
vuetify: {
customVariables: ['~/assets/variables.scss'],
theme: {
disable:true,
themes: {
light: {
primary: colors.blue,
accent: colors.blueGrey,
secondary: colors.amber,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3
}
}
}
},
/*
** Build configuration
*/
build: {
quiet: false,
optimization: {splitChunks: {chunks: "async"}, runtimeChunk: false},
splitChunks: {layouts: false, pages: false, commons: false, vendor: false},
filenames: {app: () => "main.js"},
/*
** You can extend webpack config here
*/
serverMiddleware: [
{ path: '/api', handler: '~/server/api.js' },
],
extend (config, ctx) {
}
}
}
Any help on this would be greatly appreciated!
I would expect the index page to render, but it doesn’t.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Integration with Nuxt · Issue #627 · single-spa/single ... - GitHub
I have a Nuxt app which I'd like to integrate into Single-SPA. There are various other projects in the Single-SPA application; ...
Read more >Nuxt 3 with client-side only rendering doesn't load
Right now I've switched to a server rendered application, which does work as expected, but I wonder if it's still possible to deploy...
Read more >single-spa-vue
single -spa-vue is a helper library that helps implement single-spa registered application lifecycle functions (bootstrap, mount and unmount) for use with ...
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
The solution to this is clever: Have a version of the framework/library on the server that can build a ready-to-display page. Then send...
Read more >Server Side Rendering - Nuxt
Server-side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@munawarb Hello!
I found out that the line bellow is looking for main entry file (“main”: “lib/module.js”) located in package.json 3 levels above single-spa-demo, meaning, at the root folder of the whole project
modules: [ { handler: require(path.resolve(__dirname, '../../../')) } ],
So, what I did to run the single-spa-demo in isolatation was to copy lib folder from root, and added it to single-spa-demo folder. On single-spa-demo/package.json added"main": "lib/module.js",
and dependecies required by module.js"dependencies": { "concurrently": "^5.3.0", "@nuxt/utils": "latest", "lodash.isempty": "^4.4.0", "uniqid": "^5.2.0" }
on nuxt-sub-app/nuxt.config.js . changedmodules: [ { handler: require(path.resolve(__dirname, '../')) } ],
cd single-spa-demo yarn install yarn install:all yarn serve:all
That did it for me
https://github.com/warheartvik/nuxt-single-spa-demo
Hi @warheartvik, Your solution worked 😃 I’m able to render both the sample app and also the Nuxt app I’ve created. Thanks for figuring this out. You’re a star.