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.

Cannot find module 'ziggy' or its corresponding type declarations.

See original GitHub issue

Ziggy version

v1.2.0

Laravel version

v8.42.1

Description

When using Vue3 and TypeScript, in my app.ts where I try to apply the ZiggyVue plugin using the import statement I get the following error when I try to compile:

TS2307: Cannot find module 'ziggy' or its corresponding type declarations.

When I use const ZiggyVue = require("ziggy"); it works perfectly fine and I am able to call the routes function. I had this same issue with Ziggy 1.1.0 using the route mixin. I am using laravel mix version 6. Here is my configuration below:

webpack.mix.js configurations:

const mix = require("laravel-mix");
const webpack = require("webpack");
const path = require("path");

mix.ts("resources/js/app.ts", "public/js")
    .sass("resources/sass/app.scss", "public/css")
    .sass("resources/sass/app-dark.scss", "public/css")
    .alias({
        ziggy: path.resolve("vendor/tightenco/ziggy/dist"),
    })
    .webpackConfig({
        plugins: [
            new webpack.DefinePlugin({
                __VUE_OPTIONS_API__: false,
                __VUE_PROD_DEVTOOLS__: false,
            }),
        ],
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    loader: "ts-loader",
                    options: {
                        appendTsSuffixTo: [/\.vue$/],
                    },
                    exclude: /node_modules/,
                },
                {
                    test: /\.vue$/,
                    loader: "vue-loader",
                },
            ],
        },
    })
    .vue();

Ziggy call and context

import { createApp } from "vue";
import App from "./App.vue";
import "./bootstrap";
import { Quasar } from "quasar";
// const ZiggyVue = require("ziggy"); //works
import { ZiggyVue } from 'ziggy'; //does not work

createApp(App).use(Quasar, ZiggyVue).mount("#app");

Ziggy configuration

N/A

Route definition

N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

3reactions
DSmedleycommented, Aug 14, 2021

Ok, sorry for the delay, I have not had any time to work on this. But I finally solved this issue. There were actually two different issues at hand and once I solved the first one, the second one was way easier to figure out.

The first issue, from my understanding, is because you guys wrote this in javascript and not typescript, there are no types. By default typescript will reject this with a “Could not find a declaration file for module xxxxx implicitly has an any type” error. A work around for this on my end was to add “noImplicitAny”: false to the compilerOptions in tsconfig.json.

The way that I have read and understood this issue is that for you guys to be compatible with typescript and not require us to disable noImplicitAny, you guys would have to write a types package.

With this disabled I still had an issue with the alias but both of the following configurations worked (I am using the routes directive):

app.ts

import route from "../../vendor/tightenco/ziggy/dist";
route("welcome", undefined, undefined); //my default route is named welcome for some reason
createApp(App).use(Quasar).mount("#app");
import { ZiggyVue } from "../../vendor/tightenco/ziggy/dist/vue";
createApp(App).use(Quasar).use(ZiggyVue).mount("#app");

Finally, to solve the alias issue, all I had to do was sync my aliases in the tsconfig file like so:

Using route: tsconfig.json

{
    "compilerOptions": {
        "paths": {
            "ziggy": ["vendor/tightenco/ziggy/dist"]
        },
    }
}

webpack.mix.js

.alias({
    ziggy: path.resolve("vendor/tightenco/ziggy/dist"),
})

app.ts

import route from "ziggy";
route("welcome", undefined, undefined);
createApp(App).use(Quasar).mount("#app");

Using vue plugin: tsconfig.json

{
    "compilerOptions": {
        "paths": {
            "ziggy": ["vendor/tightenco/ziggy/dist/vue"]
        },
    }
}

webpack.mix.js

.alias({
    ziggy: path.resolve("vendor/tightenco/ziggy/dist/vue"),
})

app.ts

import { ZiggyVue } from "ziggy";
createApp(App).use(Quasar).use(ZiggyVue).mount("#app");

I hope this makes sense and can help you guys understand the issue as well as help anyone else using typescript with vue3

1reaction
bakerkretzmarcommented, Aug 27, 2021

@DSmedley thanks a lot for following up with more details. I’d certainly like to eventually add types to this codebase or DefinitelyTyped. Closing this now but hopefully it’s helpful to anyone else bumping this, and we’ll keep it in mind.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ziggy-js - npm
Start using ziggy-js in your project by running `npm i ziggy-js`. There are 7 other projects in the npm registry using ziggy-js.
Read more >
cannot find module' or its corresponding type declarations vue
When using Vue3 and TypeScript, in my app. ts where I try to apply the ZiggyVue plugin using the import statement I get...
Read more >
All Laravel routes exposed. How to move it to app.js or minify if ...
Based on the Ziggy documentation and the answer attempted here I try importing it in app.js,a but it's not working. Uncaught TypeError: Cannot ......
Read more >
cannot find module '...' or its corresponding type declarations
I've been trying to deploy my nextjs app on Vercel, but got "Type error: cannot find module '...' or its corresponding type declarations" ......
Read more >
Search - appsloveworld
Coding example for the question VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations-Vue.js.
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