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

Loading an async component fails in built app, works in dev server #1694

Closed
3 tasks done
pixelspark opened this issue Jan 24, 2021 · 2 comments
Closed
3 tasks done

Loading an async component fails in built app, works in dev server #1694

pixelspark opened this issue Jan 24, 2021 · 2 comments

Comments

@pixelspark
Copy link

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

My app works fine when run with "vite". Running the app generated with "vite build" (either in production or development mode) leads to a TypeError: n.map is not a function, apparently upon loading an async component:

TypeError: n.map is not a function
    at n (preload-helper:6)
    at Slides.vue:265

Where Slides.vue:265 is:

components: {
		...
		document: defineAsyncComponent(() => import("./components/Document.vue")), // Line 265
		welcome: defineAsyncComponent(() => import("./components/Welcome.vue")),
		....
	},

The error is followed by the following error:

Component is missing template or render function. 
  at <AsyncComponentWrapper key=2 ref="document" document-id="29"  ... > 
  at <SlidesApp>

For some reason, the generated source code has what appears to be a __VITE_PRELOAD__ placeholder in it, whereas other async loaded components do not:

document:os((()=>n((()=>Promise.resolve().then((function(){return RE}))),"__VITE_PRELOAD__"))),
welcome:os((()=>n((()=>__import__("./Welcome.b9de4278.js")),["/assets/Welcome.b9de4278.js","/assets/Welcome.e4532c63.css"])))

Reproduction

Not sure how to reproduce. Repository is a company project I am trying to migrate to use Vite. Relevant config file:

import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
	plugins: [vue()],
	assetsInclude: [/\.csv$/],

	build: {
		sourcemap: true,
		outDir: "dist/client",
		rollupOptions: {
			input: {
				"index": resolve(__dirname, 'index.html')
			}
		}
	},

	optimizeDeps: {
		exclude: [
			"@dialogic/merlion"
		],
		include: [
			"parse-color", "parsimmon", "gradient-parser", "vuedraggable", // Some dependencies

			// Deep-imports from client
			"highcharts/highcharts-more",
			"highcharts/modules/sunburst",
			"highcharts/modules/networkgraph",
			"highcharts/modules/marker-clusters",
			"highcharts/modules/treemap"
		]
	},

	server: {
		port: 8080,
		https: true,
		proxy: {
			/* unlikely to be relevant */
		}
	}
});

System Info

  • vite version: vite/2.0.0-beta.47 darwin-x64 node-v14.4.0
  • Operating System: macOS Big Sur
  • Node version: v14.4.0
  • Package manager (npm/yarn/pnpm) and version: 6.14.4
@pixelspark
Copy link
Author

Wow, that's fast! I will check if this works later today.

Love your work btw, @yyx990803. Great fan of Vue, now Vue3 and Vite (coming from Webpack, it really is a godsend..).

@pixelspark
Copy link
Author

This indeed fixed my issue. Many thanks again!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
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