question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routing issues in typescript project

See original GitHub issue

Description

Navigation between pages fails when hosting Gridsome site after gridsome build, using gridsome serve, or even using a generic HTTP server.

Steps to reproduce

Create Gridsome project with typescript starter pack.

> gridsome create gridsome-ts https://github.com/cleitonper/gridsome-starter-typescript.git

Install packages, and serve content

> npm install
> gridsome serve
  • Open your browser to the link provided.
  • Click on About page.
  • Click on Home page

Expected result

It should navigate back to the Home page.

Actual result

Nothing happens. An error is thrown in the browser console

Cannot read property '_init' of undefined

If you set Webpack.mode('development') in the chainWebpack api, the exception thrown in the browser console will indicate that the error was thrown by Vue, when instantiating the component.

This error doesn’t occur when running gridsome develop.

It looks like the issue occurs when using Vue classes. This breaks:

// src/pages/Index.vue
<script lang="ts">
	import Vue from 'vue';

	export default class HomePage extends Vue {
	}
</script>

This doesn’t

// src/pages/Index.vue
<script lang="ts">
	export default {
	}
</script>

This could simply be an issue between Typescript and Vue. It’s been a while since I’ve used Typescript+Vue; things have probably changed in the interim. I’ll need to create a repo using just Typescript+Vue, without Gridsome, to see if this has anything to do with Gridsome. Could just be a bug in Vue-Router

Environment


Libs:
- gridsome version: 0.6.6
- @gridsome/cli version: 0.2.1
- Typescript@2.9.2 & Typescript@3.5.3

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 12.6.0
- Platform: Linux

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:26 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
hjvedvikcommented, Oct 22, 2019

@kororo It might be that some libraries (including Gridsome) check if a component is a function in order to resolve dynamic imports. Normally a resolved component is an object, but it can also be a function. So the fix was to not execute the function if it has a cid property.

4reactions
hjvedvikcommented, Oct 21, 2019

I finally found some time to debug this and found the cause in Gridsome. Will do some more tests and hopefully, publish a fix tomorrow 😃

Thanks for the reproduction repo @yurist38

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrate Routing in Typescript project with React-Router v5 ...
In this tutorial, we will be integrating a common element that is needed in most websites out there — routing. I will be...
Read more >
Configuring routes in NodeJS with Typescript
Today, we will continue the project by configuring our routes now, we will understand the HTTP methods and their use on the node...
Read more >
Routing not working properly in angular 6 - Stack Overflow
My project folder structure is like this. folder structure. components/app-routing.module.ts. import { NgModule } from ...
Read more >
Implementing React Router v6 with code splitting in a React ...
Create a react project with typescript template ... Create three components, Home, Topics, Settings, which will map to our three routes, /, /topics, ......
Read more >
Migrate from v6 | Ts.ED - A Node.js and TypeScript Framework ...
There is a scenario where you may run into problems if you inject PlatformRouter into your controller to dynamically create your routes. Here...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found