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

Typescript type validation error in ts-loader #1654

Open
treeandgrass opened this issue Aug 21, 2024 · 0 comments
Open

Typescript type validation error in ts-loader #1654

treeandgrass opened this issue Aug 21, 2024 · 0 comments

Comments

@treeandgrass
Copy link

webpack config

{
        test: /\.ts$/,
        use: [
          /* config.module.rule('ts').use('thread-loader') */
          {
            loader: '/Users/mouyong/company/leo-web-ai/node_modules/thread-loader/dist/cjs.js'
          },
          /* config.module.rule('ts').use('babel-loader') */
          {
            loader: '/Users/mouyong/company/leo-web-ai/node_modules/@vue/cli-plugin-typescript/node_modules/babel-loader/lib/index.js'
          },
          /* config.module.rule('ts').use('ts-loader') */
          {
            loader: '/Users/mouyong/company/leo-web-ai/node_modules/ts-loader/index.js',
            options: {
              transpileOnly: true,
              appendTsSuffixTo: [
                '\\.vue$'
              ],
              happyPackMode: true
            }
          },
          /* config.module.rule('ts').use('customPathReplacementLoader') */
          {
            loader: 'web-monorepo-custom-alias'
          }
        ]

The code implementation of web-monorepo-custom-alias is as follows

const path = require('path');
const fs = require('fs');
module.exports = function (source) {
    const callback = this.async();
    if (this.resourcePath.includes('src/utils/aiAnswer/AIAnswerScheduler')) {
        console.log(this.resourcePath)
        source = source.replaceAll('@/services/ai-answer', '../../services/ai-answer')
    }
    callback(null, source)
};

ts-loader still reports the problem that @/services/ai-answer cannot be found,Because typescript in ts-loader does type checking and does not use the replaced content

How to make typescript in ts-loader use the replaced content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant