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

No named VueLoaderPlugin export in TypeScript webpack config #1667

Closed
davelsan opened this issue Apr 24, 2020 · 3 comments
Closed

No named VueLoaderPlugin export in TypeScript webpack config #1667

davelsan opened this issue Apr 24, 2020 · 3 comments
Assignees
Labels

Comments

@davelsan
Copy link

davelsan commented Apr 24, 2020

Version

16.0.0-alpha.3

Reproduction link

File of interest:
https://github.com/davelsan/vue-next-starter/blob/master/webpack.config.ts
Full repo:
https://github.com/davelsan/vue-next-starter

Steps to reproduce

Simple version:

  1. Create a webpack.config.ts file
  2. Try to import { VueLoaderPlugin } from 'vue-loader'

Using the provided repro

  1. Comment lines [13-15] in webpack.config.ts

What is expected?

There should be a named export or a type definition for the default export that allows creating a new VueLoaderPlugin() object.

What is actually happening?

webpack.config.ts:8:10 - error TS2305: Module '"./node_modules/vue-loader/dist"' has no exported member 'VueLoaderPlugin'.

Additional Comments

The repro repository is a working Vue application built without the CLI toolchain. To work around the errors listed above, I augmented the 'vue-loader' plugin as described in the TypeScript documentation:

declare module 'vue-loader' {
  export class VueLoaderPlugin extends Plugin { }
}

This is only an issue when using a webpack.config.ts, the js version works fine.

@davelsan
Copy link
Author

davelsan commented Apr 28, 2020

Taking #1542 as inspiration, I tried adding the export directly to index.d.ts and it does fix the issue.

  import { TemplateCompiler, CompilerOptions, SFCTemplateCompileOptions } from '@vue/compiler-sfc';
+ import { Plugin } from 'webpack';
+ export class VueLoaderPlugin extends Plugin { }
  export interface VueLoaderOptions {
      transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls'];
      compiler?: TemplateCompiler;
      compilerOptions?: CompilerOptions;
      hotReload?: boolean;
      exposeFilename?: boolean;
      appendExtension?: boolean;
  }

My uneducated guess is that the problem might be in the way VueLoaderPlugin is imported and re-exported?

const webpack = require('webpack')
let VueLoaderPlugin = null
if (webpack.version && webpack.version[0] > 4) {
// webpack5 and upper
VueLoaderPlugin = require('./pluginWebpack5')
} else {
// webpack4 and lower
VueLoaderPlugin = require('./pluginWebpack4')
}
module.exports = VueLoaderPlugin

const VueLoaderPlugin = require('./plugin')

;(loader as any).VueLoaderPlugin = VueLoaderPlugin

@davelsan
Copy link
Author

Simplified the issue a bit. The current work-around is to use module augmentation in webpack.config.ts.

@sodatea sodatea added the bug label May 6, 2020
@sodatea sodatea self-assigned this May 6, 2020
sodatea added a commit to sodatea/vue-loader that referenced this issue May 9, 2020
This change fixes the emitted TypeScript type definitions

Closes vuejs#1667.
@sodatea
Copy link
Member

sodatea commented May 12, 2020

Fixed in beta 2

@sodatea sodatea closed this as completed May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants