TypeStrong / TypeStrong/ts-loader

Cannot find module - Vue + TS

Open
#1,436 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

Expected Behavior

Compile file without any error

Actual Behavior

It keeps throwing an error saying the file does not exist.

Steps to Reproduce the Problem

In my case, I have a Laravel + InertiaJS project with some Vue components.

I am importing the question.vue component inside the questionBuilder.vue, but, for some reason, it keeps throwing that error, I have no idea why. The file is there, my IDE (PHPStorm) identifies the file as it's on a valid path.
Also, the changes I made are actually being compiled to the bundle.js file, so do you guys have any idea of what could be wrong?
I have also written my own webpack.config.js to see if it's related to laravel mix but I had the same issue.

Thanks in advance.

image

webpack.config.js

const path = require('path')

module.exports = {
    resolve: {
        extensions: ['.ts', '.js', '.styl'],
        alias: {
            '@components': path.resolve(__dirname, 'resources/js/components'),
            '@data': path.resolve(__dirname, 'resources/js/data'),
            '@layouts': path.resolve(__dirname, 'resources/js/layouts'),
            '@pages': path.resolve(__dirname, 'resources/js/pages'),
            '@': path.resolve(__dirname, 'resources/js'),
            '@css': path.resolve(__dirname, 'resources/css')
        }
    },
    module: {
        rules: [
            {
                test: /\.mjs$/,
                resolve: { fullySpecified: false },
                include: /node_modules/,
                type: 'javascript/auto'
            },
            {
                test: /\.pug$/,
                loader: 'pug-plain-loader'
            },
            {
                test: /\.ts$/,
                loader: 'ts-loader',
                options: { appendTsSuffixTo: [/\.vue$/] },
                exclude: /node_modules/
            }
        ]
    }
}

tsconfig.json

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        // this enables stricter inference for data properties on `this`
        "strict": true,
        "noPropertyAccessFromIndexSignature": true,
        "noUncheckedIndexedAccess": true,
        "noImplicitAny": false,
        "jsx": "preserve",
        "moduleResolution": "node",
        "baseUrl": ".",
        "paths": {
            "@/*": ["resources/js/*"],
            "@components/*": ["resources/js/components/*"],
            "@data/*": ["resources/js/data/*"],
            "@layouts/*": ["resources/js/layouts/*"],
            "@pages/*": ["resources/js/pages/*"]
        }
    }
}

webpack.mix.js (laravel mix)

const mix = require('laravel-mix')

mix.js('resources/js/app.ts', 'public/js')
    .vue()
    .stylus('resources/css/global.styl', 'public/css/')
    .webpackConfig(require('./webpack.config'))

if (mix.inProduction()) {
    mix.version()
}
Location of a Minimal Repository that Demonstrates the Issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the compile error from the reported Vue and TypeScript setup, then inspect webpack.config.js, tsconfig.json, and webpack.mix.js together. Trace resolution of the question.vue import from questionBuilder.vue and identify why compilation reports the file as missing. Done means the minimal project compiles without that module error using the documented configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.